VBA to update cross-reference in a word documents

zoog25

Active Member
Joined
Nov 21, 2011
Messages
418
Hello all,

I'm using some coding to first, select from drop down form field in a word document based on a select case method.

My question is that in another part of the word document, i have a cross reference to this field and i want to know is how do i update this field using code.

VBA Code:
Dim Wordapp As Word.Application
Dim TPws As Worksheet

Set TPws = ThisWorkbook.Worksheets("Tract Parcels")

Dim wFile As String
wFile = ActiveWorkbook.Path & "\x.docx"
If Dir(wFile) <> "" Then
    Wordapp.Documents.Open (wFile)
    Wordapp.Visible = True
Else
    MsgBox "File does not exists"
    'do actions
End if

Select Case TPws.Cells(rw, "D")
    Case "PVT AGR"
        Wordapp.ActiveDocument.FormFields("DDNOC").DropDown.Value = 2
    Case Else
        Wordapp.ActiveDocument.FormFields("DDNOC").DropDown.Value = 1
End Select

The form field being referenced in the document is title DDNOC. There are two options as of right now. I need the reference field to update based on the value select here.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top