Free Support Forum - aspose.com

Vb.net Sub UpdateMergeFields change from Word.Interop to Aspose.Word

Appreciate your assistance with changing the following subroutine so it uses Aspose.Word instead of Microsoft.Office.Interop.Word

Public Shared Sub UpdateMergeFields(ByRef path As String)

Try

if string.Empty.Equals(Configuration.ConfigurationSettings.AppSettings("UpdateMergeFields") & "")

exit Sub

End If

Dim app As ApplicationClass

Dim doc As DocumentClass

Try

If Not System.IO.File.Exists(path) Then

Exit Sub

End If

doc = app.Documents.Open(path)

doc.ComputeStatistics(WdStatistic.wdStatisticPages)

If doc.Sections.Count > 0 Then

doc.Sections(1).Headers(WdHeaderFooterIndex.wdHeaderFooterEvenPages).Range.Fields.Update()

doc.Sections(1).Headers(WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range.Fields.Update()

doc.Sections(1).Headers(WdHeaderFooterIndex.wdHeaderFooterPrimary).Range.Fields.Update()

End If

doc.Range.Fields.Update()

doc.Save()

Catch

' ignore error

Finally

If Not doc Is Nothing Then

doc.Close()

End If

If Not app Is Nothing Then

app.Quit()

End If

End Try

Catch ex As Exception

' ignore error

End Try

End Sub

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your interest in Aspose.Words. As I can see your code just update fields in the document. Currently Aspose.Words can update DOCPROPERTY and DOCVARIABLE fields only. See the following link for more information.

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/aspose.words.range.updatefields.html

Also see FAQ.

Best regards.