Function TAutoMerge.ProcessMerge(FSource, FData, FOutput : string) : boolean; var MSWord : Variant;i, NumDocs : integer;Found : boolean;s, LastOLECommand : string;begin ProcessMerge := False;tryLastOLECommand := 'Creating OLE Object.';MSWord := CreateOLEObject('Word.Basic');LastOLECommand := 'Show MS Word.';MSWord.AppShow;Application.ProcessMessages; LastOLECommand := 'Open document file >' + FSource + '<.';MSWord.FileOpen(Name := FSource, ConfirmConversions := 0,ReadOnly := 1, AddToMru := 0, PasswordDoc := '',PasswordDot := '', Revert := 0,WritePasswordDoc := '',WritePasswordDot := '');LastOLECommand := 'Screen updating = false.';MSWord.ToolsOptionsSpelling(AutomaticSpellChecking := 0);LastOLECommand := 'Set background printing to off.';MSWord.ToolsOptionsPrint(Background := 0); Application.ProcessMessages;LastOLECommand := 'Open Data file >' + FData + '<.';MSWord.MailMergeOpenDataSource(Name := FData, ConfirmConversions := 0,ReadOnly := 1, LinkToSource := 1,AddToMru := 0,PasswordDoc := '', PasswordDot := '',WritePasswordDoc := '', WritePasswordDot := '',Connection := '', SQLStatement := '',SQLStatement1 := '',Revert := 1); LastOLECommand := 'Start the Mail Merge.';MSWord.MailMerge(CheckErrors := 2, Destination := 1,MergeRecords:= 0,From := '', To := '', Suppression := 0,MailSubject := '',MailAsAttachment := 0, MailAddress := ''); LastOLECommand := 'Set up for SendKeys to select printer.';Application.ProcessMessages;MSWord.AppShow;s := '{home}%l{enter}{home}%n' + FOutput + '{tab}{enter}{home}{enter}';// sdd 1.1MSWord.SendKeys(s, -1);MSWord.MailMergeToPrinter;Application.ProcessMessages; ProcessMerge := True;LastOLECommand := 'All done with merge.';excepton EOleException dobegininc(TotalOLEErrors);lblStatus.caption := LastOLECommand;if (TotalOLEErrors >= TOTALOLEERRORS_MAX) thenbegins := 'Имеется по крайней мере одна ошибка OLE (' +IntToStr(TotalOLEErrors) + '), последней ошибкой было >' + LastOLECommand + '<.';ShowMessage(s);end;endend;end; |
[000194]