VBA to update cross-reference in a word documents

zoog25

Active Member
Joined
Nov 21, 2011
Messages
414
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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,785
Messages
5,833,690
Members
430,222
Latest member
Nickkarl

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
Top