How to: Resize Bookmark Controls
Updated: July 2008
The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office.
For more information, see Features Available by Application and Project Type.
You set the size of a Bookmark control when you add it to a Microsoft Office Word document. You can also resize it at a later time.
There are three ways to resize a bookmark:
Add or remove text in the Bookmark control.
Whenever you add text in a bookmark, the size of the bookmark automatically increases to contain the new text. When you delete text, the size of the bookmark automatically decreases.
This is useful if you are changing the size by only a few characters.
Recreate the Bookmark control.
This is useful if there is a substantial change in the size or location of a bookmark.
In document-level projects, you can add Bookmark controls to the document in your project at design time or at run time. Starting in Visual Studio 2008 Service Pack 1 (SP1), you can add Bookmark controls to any open document at run time by using an application-level add-in for Word 2007. For more information, see How to: Add Bookmark Controls to Word Documents.
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.
To resize a bookmark in a document-level project at design time
To resize a bookmark in a document-level project at run time
The following code example adds five characters to the start of a bookmark named SampleBookmark. This code assumes that there are at least five characters of text before the bookmark.
The following code example adds five characters to the end of the same bookmark. This code assumes that there are at least five characters of text after the bookmark.
To resize a bookmark in an application-level project at run time
Microsoft.Office.Tools.Word.Document vstoDocument = this.Application.ActiveDocument.GetVstoObject(); vstoDocument.ActiveWindow.View.ShowBookmarks = true; vstoDocument.Paragraphs.Range.InsertParagraphBefore(); Word.Range firstParagraph = vstoDocument.Paragraphs.Range; firstParagraph.Text = "123456789abcdefghijklmnopqrstuvwxyz"; Microsoft.Office.Tools.Word.Bookmark sampleBookmark = vstoDocument.Controls.AddBookmark(firstParagraph, "bookmark1"); sampleBookmark.Start = sampleBookmark.Start + 5; sampleBookmark.End = sampleBookmark.End - 5;
You can resize a bookmark in a document-level project by adding a new bookmark that has the same name as the existing bookmark, but that has a different size.
To recreate a bookmark in a document-level project at design time
Select the text to be included in the new Bookmark control.
On the Insert menu, click Bookmark.
In the Bookmark dialog box, select the name of the bookmark that you want to resize and click Add.