Word automation with vb.net

Discussion in 'Microsoft VB .NET' started by William LaMartin, Jul 30, 2004.

  1. 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()
     
    William LaMartin, Jul 30, 2004
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. scorpion53061

    Word Automation in VB.NET and Printing

    scorpion53061, Jan 21, 2004, in forum: Microsoft VB .NET
    Replies:
    4
    Views:
    414
    scorpion53061
    Jan 22, 2004
  2. Fido

    Word Automation with vb.net

    Fido, Mar 9, 2004, in forum: Microsoft VB .NET
    Replies:
    0
    Views:
    205
  3. Robin Tucker
    Replies:
    1
    Views:
    438
    Jean-Guy Marcil
    Sep 15, 2004
  4. Andrew Cranwell

    Word 2000 / VB.Net Automation Help Required

    Andrew Cranwell, Jul 28, 2005, in forum: Microsoft VB .NET
    Replies:
    2
    Views:
    401
    Andrew
    Aug 18, 2005
  5. apondu
    Replies:
    1
    Views:
    324
    Newbie Coder
    Jul 23, 2007
Loading...

Share This Page