Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleOpen Word and go to a bookmark
KeywordsOffice, Word, bookmark
CategoriesOffice
 
Create a Word.Application server object. Use its Selection.GoTo method to go to the bookmark. Then use Selection.TypeText to enter text at that point if you like.

Note that this project contains a reference to the Microsoft Word 8.0 Object Library. You may need to use a different library if you have a different version of Word.

 
Private WordServer As Word.Application

Private Sub Command1_Click()
Dim file_name As String
Dim file_path As String
Dim file_title As String
Dim txt As String
Dim new_txt As String
Dim pos As Integer

    Screen.MousePointer = vbHourglass
    Command1.Enabled = False
    DoEvents

    file_name = txtFilename.Text
    file_title = Mid$(file_name, InStrRev(file_name, "\") + _
        1)
    file_path = Left$(file_name, Len(file_name) - _
        Len(file_title))

    WordServer.Visible = True

    WordServer.ChangeFileOpenDirectory file_path
    WordServer.Documents.Open _
        FileName:=file_title, _
        ConfirmConversions:=False, _
        ReadOnly:=False, _
        AddToRecentFiles:=False, _
        PasswordDocument:="", _
        PasswordTemplate:="", _
        Revert:=False, _
        WritePasswordDocument:="", _
        WritePasswordTemplate:="", _
        Format:=wdOpenFormatAuto

    WordServer.Selection.GoTo _
        What:=wdGoToBookmark, _
        Name:="Disclaimer"
    WordServer.Selection.Find.ClearFormatting
    With WordServer.Selection.Find
        .Text = ""
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With

    WordServer.Selection.TypeText _
        Text:="<Here is the bookmark>"

    Screen.MousePointer = vbDefault
    Command1.Enabled = True
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated