newtotheforum2019
New Member
- Joined
- Dec 17, 2019
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
Hi,
New to VBA so please bear with me. I want to create Excel VBA code that asks the user to open a pre-existing Word document with text form fields and input existing Excel data in these form fields. I currently have code that writes the Excel data into the Word text form field, but am lost as to converting the "Set wd= wdApp.Documents.Open("FilePath") line into a dialog box. Any assistance would be appreciated.
Thanks.
Sub NewMacro()
Dim wdApp As Object, wd As Object, ac As Long, ws As Worksheet
Set ws = Sheets("Tables")
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wd = wdApp.Documents.Open("C:\Test\Test.docx")
wdApp.Visible = True
With wd
.FormFields("CustomerName").Result = ws.Range("D4").Value
End With
Set wd = Nothing
Set wdApp = Nothing
End Sub
New to VBA so please bear with me. I want to create Excel VBA code that asks the user to open a pre-existing Word document with text form fields and input existing Excel data in these form fields. I currently have code that writes the Excel data into the Word text form field, but am lost as to converting the "Set wd= wdApp.Documents.Open("FilePath") line into a dialog box. Any assistance would be appreciated.
Thanks.
Sub NewMacro()
Dim wdApp As Object, wd As Object, ac As Long, ws As Worksheet
Set ws = Sheets("Tables")
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wd = wdApp.Documents.Open("C:\Test\Test.docx")
wdApp.Visible = True
With wd
.FormFields("CustomerName").Result = ws.Range("D4").Value
End With
Set wd = Nothing
Set wdApp = Nothing
End Sub