Open a word Doc and GoTo a specified Bookmark

sambo

Registered User.
Local time
Today, 07:54
Joined
Aug 29, 2002
Messages
289
I would like to Open a word Doc and Go To a specified Bookmark in that document.
The document will be recieved in the OnClick Event.

I want to do something like this...

On Click =GoToDoc("help.doc", "#CheckIn") 'The Call

Function GoToDoc(whatDoc As String, whatBookMark As String) 'the function

Application.Document.Open(whatDoc)
GoTo.BookMark(whatBookMark)

End Function


Is something like this possible.
And please don't suggest the Microsoft Help Workshop, I've been working with that all day to no avail, so I'm just creating my own method.

Thanks
 
Here is some simple code that uses automation to open a word doc and goto a bookmark:
Code:
Private Sub openDoc_Click()
    Dim objWord As Word.Application
    Dim strDocPath As String
    
    strDocPath = "C:\My Documents\Test.doc"
    Set objWord = New Word.Application
    
    objWord.Documents.Open strDocPath
    objWord.Visible = True
    
    objWord.Selection.Goto wdGoToBookmark, , , "MyBookmark"
    Set objWord = Nothing
End Sub
You might want to look up automation though, as there is a lot more to it then this, such as checking to see if word is already running.
And you need to set a reference to word in VBA.
Tools -> References -> Microsoft Word 9.0 Obect Library (Office 2000)

Dave
 
Thanks,
That Word 9.0 Reference proved to be crucial for using the GoTo.

Here is a way that I figured out to do it without the Goto, but this only sets the cursor to the bookmark, it doesn't actually Queue up the desired bookmark. Yours is better...

Public Function Help(BMark As String)

Dim loc As String, str As String, objWord As Object


Set objWord = CreateObject("Word.Application") 'Create the doc space
objWord.Visible = True 'show the word doc on top of windows
loc = Application.CurrentProject.Path 'set the folder
str = "\RMA Interface Help.doc" 'set the document
str = loc + str
objWord.Documents.Add str 'open the document in Word

With objWord.Application.ActiveDocument
.bookmarks(BMark).Select 'go to the desired bookmark
End With

Set objWord = Nothing
End Function


Thanks again
 

Users who are viewing this thread

Back
Top Bottom