We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Text between two bookmarks


It’s possibe to select an replace text between two Bookmarks (BMStart, BMEnd) on an existing document?

[BMStarart]Text Text Text[BMEnd]


Hi Stefan,

Thanks for your inquiry. Sure, you can get or set the text enclosed in the bookmark using Bookmark.Text property. The following example shows how to get or set bookmark name and text.

Document doc = new Document(MyDir + “Bookmark.doc”);

// Use the indexer of the Bookmarks collection to obtain the desired bookmark.
Bookmark bookmark = doc.Range.Bookmarks[“MyBookmark”];

// Get the name and text of the bookmark.
string name = bookmark.Name;
string text = bookmark.Text;

// Set the name and text of the bookmark.
bookmark.Name = “RenamedBookmark”;
bookmark.Text = “This is a new bookmarked text.”;

Hope, this helps.

Best regards,


Thanks for your answer, but I think, it’s not exactly what I mean.


An existing Word-Document has two Bookmarks - a start-Bookmark and an end-Bookmark. There is text between the Bookmarks. Now I have to get the Text between this two Bookmarks and replace it.

|This is Text|


| ________ Bookmark-End


Here a sample how I used in in Office:


pos = docword.Bookmarks.Item(“BMStart”).Start


pos2 = docword.Bookmarks.Item(“BMEnd”).Start

objword.Selection.SetRange(Start:=pos, End:=pos2)

objword.Selection.TypeText(“New Text”)

Kind regards

Hi Stefan,

Thanks for the details. Please refer to the following section of documentation:

I hope, this helps.

Best regards,