To update bookmark contents using a 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.
Shared Sub BookMarkReplace( _
ByRef bookmark As Microsoft.Office.Tools.Word.Bookmark, _
ByVal newText As String)
static void BookMarkReplace(
ref Microsoft.Office.Tools.Word.Bookmark bookmark,
string newText)
{
Assign the newText string to the Text property of the Microsoft.Office.Tools.Word..::.Bookmark.
bookmark.Text = newText
End Sub
bookmark.Text = newText;
}
To update bookmark contents using a Word Bookmark object
Create a procedure that has a bookmark argument for the name of the Microsoft.Office.Interop.Word..::.Bookmark, and a newText argument for the string to assign to the Range..::.Text property of the bookmark.
Friend Sub BookMarkReplaceNative( _
ByVal bookmark As Word.Bookmark, _
ByVal newText As String)
internal void BookMarkReplaceNative(
Word.Bookmark bookmark,
string newText)
{
Assign the newText string to the Range..::.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.
Dim rng As Word.Range = bookmark.Range
Dim bookmarkName As String = bookmark.Name
bookmark.Range.Text = newText
Me.Bookmarks.Add(Name:=bookmarkName, Range:=rng)
End Sub
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 an application-level add-in. This example uses the active document.
Dim rng As Object = bookmark.Range
Dim bookmarkName As String = bookmark.Name
bookmark.Range.Text = newText
Me.Application.ActiveDocument.Bookmarks.Add(Name:=bookmarkName, Range:=rng)
End Sub
object rng = bookmark.Range;
string bookmarkName = bookmark.Name;
bookmark.Range.Text = newText;
Word.Document document = this.Application.ActiveDocument;
document.Bookmarks.Add(bookmarkName, ref rng);
}
Tasks
Concepts