it may need the following units: ComObj, word2000, System.Variants, but I don't remember for sure
var NewDoc, WordApp: Variant;
......
try WordApp:=CreateOLEObject('Word.Application'); // NewDoc := WordApp.Documents.Open(aFileName); // open existing word file NewDoc := WordApp.Documents.Add; // or start a new document - use Open or Add, not both WordApp.Selection.EndKey(wdStory); // jump at the end of a document // WordApp.Selection.HomeKey(wdStory); // this would jump to the top of a document WordApp.Selection.TypeText('some text line 1'); WordApp.Selection.InsertBreak(wdLineBreak); // insert new line, also know as #13#10 or CRLF // WordApp.Selection.InsertBreak(wdSectionBreakNextPage); // this would insert a page break WordApp.Selection.TypeText('some text line 2'); // NewDoc.Save; // simply save it if it was opened from an existing file NewDoc.SaveAs(aOtherfileName); // or save it under specific name if it was created as new or we want to rename it WordApp.Visible:=true; WordApp.Activate;
it may need the following units: ComObj, word2000, System.Variants,
ReplyDeletebut I don't remember for sure
var
NewDoc, WordApp: Variant;
......
try
WordApp:=CreateOLEObject('Word.Application');
// NewDoc := WordApp.Documents.Open(aFileName); // open existing word file
NewDoc := WordApp.Documents.Add; // or start a new document - use Open or Add, not both
WordApp.Selection.EndKey(wdStory); // jump at the end of a document
// WordApp.Selection.HomeKey(wdStory); // this would jump to the top of a document
WordApp.Selection.TypeText('some text line 1');
WordApp.Selection.InsertBreak(wdLineBreak); // insert new line, also know as #13#10 or CRLF
// WordApp.Selection.InsertBreak(wdSectionBreakNextPage); // this would insert a page break
WordApp.Selection.TypeText('some text line 2');
// NewDoc.Save; // simply save it if it was opened from an existing file
NewDoc.SaveAs(aOtherfileName); // or save it under specific name if it was created as new or we want to rename it
WordApp.Visible:=true;
WordApp.Activate;
finally
NewDoc:=unassigned;
WordApp:=unassigned;
end;
constants are defined in word2000 like this:
const
wdSectionBreakNextPage = $00000002;
wdSectionBreakContinuous = $00000003;
wdSectionBreakEvenPage = $00000004;
wdSectionBreakOddPage = $00000005;
wdLineBreak = $00000006;
wdPageBreak = $00000007;
wdColumnBreak = $00000008;
wdLineBreakClearLeft = $00000009;
wdLineBreakClearRight = $0000000A;
wdTextWrappingBreak = $0000000B;
- I hope it helps. I put in a few other interesting things that I painfully discovered over a few sleepless nights.