Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleOpen Word and go to a bookmark in VB .NET
KeywordsOffice, Word, bookmark
CategoriesOffice, Utilities, VB.NET
 
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 10.0 Object Library. You may need to use a different library if you have a different version of Word.

 
' Open the Word document, go to TheBookmark,
' type some text, and display the document,
' leaving the Word server running.
Private Sub cmdOpen_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles cmdOpen.Click
    Dim file_name As String
    Dim file_path As String
    Dim file_title As String
    Dim word_server As Word.Application

    Cursor = System.Windows.Forms.Cursors.WaitCursor
    cmdOpen.Enabled = False
    Application.DoEvents()

    file_name = txtFileName.Text
    file_title = _
        file_name.Substring(file_name.LastIndexOf("\") + 1)
    file_path = file_name.Substring(0, _
        file_name.LastIndexOf("\"))

    word_server = New Word.Application()
    word_server.ChangeFileOpenDirectory(file_path)
    word_server.Documents.Open( _
        FileName:=file_title, _
        ConfirmConversions:=False, _
        ReadOnly:=False, _
        AddToRecentFiles:=False, _
        PasswordDocument:="", _
        PasswordTemplate:="", _
        Revert:=False, _
        WritePasswordDocument:="", _
        WritePasswordTemplate:="", _
        Format:=Word.WdOpenFormat.wdOpenFormatAuto)

    word_server.Selection.GoTo( _
        What:=Word.WdGoToItem.wdGoToBookmark, _
        Name:="TheBookmark")
    word_server.Selection.TypeText( _
        Text:="<Here is the bookmark>")
    word_server.Visible = True

    Cursor = System.Windows.Forms.Cursors.Default
    cmdOpen.Enabled = True
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated