Hello,
I am fairly new to Office VBA, so please be patient with me...
Using VBA from Excel 2010, I am opening a Word document, to enter some tekst in some of the bookmarks of this Word document.
By clicking on the first button everything works fine:
Code
Private Sub ButtonStep0OK_Click()
Dim wdApp As Word.Application
Dim myDoc As Word.Document
name = UserFormOfferte.CB_name.Value
Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set myDoc = wdApp.Documents.Add("C:\documentname.docx")
With myDoc.Bookmarks
.Item("firstname").Range.Text name
End With
End Sub
Display More
The Word document remains open while the user goes to a second page of the form, enters some information and presses a second OK-button.
Now below code does NOT work as the file is already open. A second word document is opened, where the info is added, while I want it to be added in the already open document.
What needs to be changed to refer to the already open document?
Code
Private Sub ButtonStep1OK_Click()
Dim wdApp As Word.Application
Dim myDoc As Word.Document
place = UserFormOfferte.CB_place.Value
Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set myDoc = wdApp.Documents.Add("C:\documentname.docx")
With myDoc.Bookmarks
.Item("placebirth").Range.Text place
End With
End Sub
Display More