Events
Apr 8, 3 PM - May 28, 7 AM
Sharpen your AI skills and enter the sweepstakes to win a free Certification exam
Register now!This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
You can insert text into a placeholder bookmark in a Microsoft Office Word document so that you can retrieve the text at a later time, or to replace text in a bookmark. If you are developing a document-level customization, you can also update text in a Bookmark control that is bound to data. For more information, see Bind data to controls in Office solutions.
Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for Word. For more information, see Features available by Office application and project type.
The bookmark object can be one of two types:
A Bookmark host control.
Bookmark controls extend native Bookmark objects by enabling data binding and exposing events. For more information about host controls, see Host items and host controls overview.
A native Bookmark object.
Bookmark objects do not have events or data binding capabilities.
When you assign text to a bookmark, the behavior differs between a Bookmark and a Bookmark. For more information, see Bookmark control.
Create a procedure that takes a bookmark
argument for the name of the bookmark, and a newText
argument for the string to assign to the Text property.
Note
Assigning text to the Text or FormattedText property of a Bookmark control does not cause the bookmark to be deleted.
Assign the newText string to the Text property of the Bookmark.
Create a procedure that has a bookmark
argument for the name of the Bookmark, and a newText
argument for the string to assign to the Text property of the bookmark.
Note
Assigning text to a native Word Bookmark object causes the bookmark to be deleted.
Assign the newText string to the Text property of the bookmark, which automatically deletes the bookmark. Then re-add the bookmark to the Bookmarks collection.
The following code example can be used in a document-level customization.
object rng = bookmark.Range;
string bookmarkName = bookmark.Name;
bookmark.Range.Text = newText;
this.Bookmarks.Add(bookmarkName, ref rng);
}
The following code example can be used in a VSTO Add-in. This example uses the active document.
Events
Apr 8, 3 PM - May 28, 7 AM
Sharpen your AI skills and enter the sweepstakes to win a free Certification exam
Register now!