Author: Andreas Heidenreich
How can I replace Text in Bookmarks in WORD?
Answer:
When Word is connected via OLE, you can use bookmarks to fill in text into an
existing template or document.
The first step is connecting to WORD, either with an OLE-Object or in an
OLE-Control.
The Server You connect to should be WORD.Document, not WORD.Application. With this,
it is easier to control that You always word on the right Document.
Finding an Replacing a bookmark goes like that:
1 var2 Doc: Variant;
3 Result: string;
4 Bookmark: string;
5 Startpos, Endpos: longint;
6 begin7 // You already are connected to a WORD.Document Object!8 //9 Result := 'anything';
10 Bookmark := 'bookmark 20';
11 // Replace the Text:12 Doc.Bookmarks.Items('bookmark 20').range.text := Result;
13 // done this, You have lost the Bookmark, but integrated the Text14 end;