How to: Add Bookmark Controls to Word Documents
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

How to: Add Bookmark Controls to Word Documents

Note Required applications

The features in this topic are available only if you have the required applications installed.

For more information, see Features Available by Product Combination.

  • One of these development environments:

    VSTO 2005

    -or-

    Visual Studio Team System

  • Microsoft Office 2003

There are several ways to add Bookmark controls to your Microsoft Office Word 2003 document.

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

  • From within Word.

    You can add the Bookmark control to your document in the same manner you would add the native bookmark object from within the application. The advantage of adding it this way is that you can name your control at the time you create it.

  • From the Visual Studio Toolbox.

    You can drag the Bookmark control from the Toolbox to your document. You might want to choose this way if you are already using the Toolbox to add Windows Forms controls to your document.

  • From the Data Sources Window.

    You can drag the Bookmark control to your document from the Data Sources window. This is useful when you want to bind the control to data at the time of creation of the control. You can add the host control in the same way you would add a Windows Form control from the Data Sources window. For more information, see Data Binding and Windows Forms.

  • Programmatically.

    You can add the Microsoft.Office.Tools.Word.Bookmark control programmatically. This enables you to create the host controls in response to events. Dynamically created bookmarks are not persisted in the document as host controls when the document is closed. However, a native bookmark remains in the document. You can use the Microsoft.Office.Tools.Word.ControlCollection.AddBookmark(Microsoft.Office.Interop.Word.Bookmark,System.String) method to change the native Microsoft.Office.Interop.Word.Bookmark into a Microsoft.Office.Tools.Word.Bookmark control the next time the document is opened. For more information, see Adding Controls to Office Documents at Run Time.

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To add a Bookmark host control to a document using the Bookmark dialog box

  1. Select the data you want to include in the bookmark.

  2. From in the Insert menu, select Bookmark.

  3. In the Bookmark dialog box, type the name of the bookmark in the Bookmark name box and click Add.

To add a Bookmark control to a document using the Toolbox

  1. Open the Toolbox and click the Word Controls tab.

  2. Click Bookmark and drag it to the document.

    The Add Bookmark dialog box appears.

  3. Select the data you want to include in the bookmark.

  4. Click OK.

    If you do not want the default name given to the control, you can change the name in the Properties window.

You can also add controls programmatically to a document at run time. In the example below, a Bookmark control is added to the first paragraph in the document in the Startup event of ThisDocument.

To add a Bookmark control to a document programmatically

  • In the Startup event of ThisDocument, insert the following code to add the Bookmark control to the first paragraph in the document:

    Microsoft.Office.Tools.Word.Bookmark firstParagraph;
    firstParagraph = this.Controls.AddBookmark(this.Paragraphs[1].Range,
        "FirstParagraph");
    
    
    NoteNote

    If you want create a Microsoft.Office.Tools.Word.Bookmark control from an existing Microsoft.Office.Interop.Word.Bookmark, use the AddBookmark method and pass in the existing Microsoft.Office.Interop.Word.Bookmark.

See Also

Show:
© 2016 Microsoft