Inserting Text into Word 97 Doc using Bookmarks
Hi,
I'm trying to get Delphi to insert text into predfined bookmarks in a Word
97 document, which is stored in an OLEContainer control. My code is as
follows :-
procedure TfrmEditor.FormShow(Sender: TObject);
var
Doc : OleVariant;
begin
With oleWord97 do {oleWord97 is the name of the OLEContainer}
begin
CreateObjectFromFile('T:\pre_gast.dot', false);
DoVerb(ovShow);
Doc := OleObject;
Doc.Bookmarks.Item('bk_VNo').Select;
{everything works up to this point}
Doc.Selection.InsertAfter(frmPatients.edVNo.text); {doesn't work}
end;
end;
The code shown above creates the document and displays it in the
OLEContainer, and invokes Word 97. The correct bookmark is selected, but
whatever I do to try to insert text at that bookmark, I get an error -
'Method not supported by OLE Object'.
What should I be doing to insert text correctly ? I tried using
'Doc.Range.InsertBefore('Hello') but this inserts 'Hello' at the beginning
of the document and not at the selected bookmark. Using
'Doc.Range.Insert('Hello')' gives the 'Method not supported by OLE Object
error'. I also get an error with 'Doc.Selection.Insert('Hello')'
The aim is to create a single letter by inserting data from a database into
the parts defined by the bookmarks. I'd aprreciate some help with this.
Thanks in advance,
Brian.