Mega Code Archive

 
Categories / Delphi / Activex OLE
 

Bookmarks in WORD

Title: Bookmarks in WORD Question: 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: Var Doc: Variant; Result: String; Bookmark: String; Startpos, Endpos: longint; begin // 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 end;