Replace Text in Bookmarks in WORD (Views: 100)


How can I replace Text in Bookmarks in WORD?


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:

  Doc: Variant;
  Result: string;
  Bookmark: string;
  Startpos, Endpos: longint;
  // You already are connected to a WORD.Document Object!
  Result := 'anything';
  Bookmark := 'bookmark 20';
  // Replace the Text:
  Doc.Bookmarks.Items('bookmark 20').range.text := Result;
  // done this, You have lost the Bookmark, but integrated the Text

<< Back to main page