I had no trouble doing this sort of thing in VBA. What I want to do is open
a Word document, change the values of its fields that are of DOCVariable
type save the changes and exit. But in VB.net I can not figure out the code
to change the values of the fields.
The code below, cycles through all of the fields in the document displaying
the field type and what the current text is.
How do I change the value of the fields?
'need references to Office and word object libraries
Dim oWordApp As New Microsoft.Office.Interop.Word.Application
oWordApp.Visible = True
Dim docPath As String = Application.StartupPath & "\Test2.doc"
oWordApp.Documents.Open(docPath)
Dim i As Integer
For i = 1 To oWordApp.ActiveDocument.Fields.Count - 1
MsgBox("Type: " &
oWordApp.ActiveDocument.Fields.Item(i).Type.ToString)
MsgBox("Result.Text: " &
oWordApp.ActiveDocument.Fields.Item(i).Result.Text())
Next
oWordApp.Quit()
|