2008. november 4., kedd

Replace Text in Bookmarks in WORD


Problem/Question/Abstract:

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;

Nincsenek megjegyzések:

Megjegyzés küldése