By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,041 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,041 IT Pros & Developers. It's quick & easy.

Word automation with vb.net

P: n/a
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.ToStri ng)
MsgBox("Result.Text: " &
oWordApp.ActiveDocument.Fields.Item(i).Result.Text ())
Next
oWordApp.Quit()
Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.