Hi. I have some buttons on a userform which all relate to bookmarks in a word document. The code I have works fine. Here it is.
Private Sub CMB_02_Run_Click()
Unload Me
Dim wrdApp As Object
Dim wrdDoc As Object
Dim myFile As String
myFile = "C:\My Stuff To Keep\Excel\PRJ BuskingStrummy\Busking Strummy.docm"
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open(myFile)
wrdApp.ActiveDocument.Bookmarks("A02").Select
Set wrdApp = Nothing
Set wrdDoc = Nothing
End Sub
Display More
However, there is a potential for there to be hundreds and hundreds of bookmarks in the document. Each of these will require buttons on a multipage form. What I'm trying to do is on clicking the button enter the name of the bookmark ( in the case above "A02") and then send it to the rest of the code as a sub. The string name I'm going with at the moment is bmRef (ie bookmark reference). So the code should look something like this. However this code below would now be a subroutine the button only sending bmRef to the public variable
Private Sub CMB_02_Run_Click()
Unload Me
Dim wrdApp As Object
Dim wrdDoc As Object
Dim myFile As String
myFile = "C:\My Stuff To Keep\Excel\PRJ BuskingStrummy\Busking Strummy.docm"
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open(myFile)
wrdApp.ActiveDocument.Bookmarks(bmRef).Select
Set wrdApp = Nothing
Set wrdDoc = Nothing
End Sub
Display More
The problem I'm having is that I get an error whenever I run this.
I have declared bmRef as a public string but I can't seem to get it to work. Any ideas?