如何等待word打印完毕再退出(50分)

  • 主题发起人 主题发起人 少爷的拐杖
  • 开始时间 开始时间

少爷的拐杖

Unregistered / Unconfirmed
GUEST, unregistred user!
我调用word,用数据库中的内容替换掉word中的内容来打印,
但是因为发出打印命令后就执行了word退出的语句,造成
无法打印的问题,是否能等待...直到全部发送到打印机再退出?
procedure TFm_Property_D_T.SpeedButton6Click(Sender: TObject);
var
sFileName: string;
BS : TADOBlobStream;
ItemIndex :OleVariant;
FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert,
WritePasswordDocument, WritePasswordTemplate, Format: OleVariant;

FindText, MatchCase, MatchWholeWord, MatchWildcards, MatchSoundsLike,
MatchAllWordForms, TForward, Wrap, TFormat, ReplaceWith, Replace: OleVariant;

SaveChanges, OriginalFormat, RouteDocument: OleVariant;

begin
........
try
WordApplication1.Connect;
WordApplication1.Visible:= False;
except
Application.MessageBox('启动MS Word时发生错误。请确认您安装了MS Word并且能够使用。','操作失败',Mb_ok+Mb_IconInformation);
end;
FileName := sFileName;
ConfirmConversions := False;
ReadOnly := False;
AddToRecentFiles := False;
PasswordDocument := '';
PasswordTemplate := '';
Revert := True;
WritePasswordDocument := '';
WritePasswordTemplate := '';
Format := wdOpenFormatDocument;

WordApplication1.Documents.Open( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format );

Application.ProcessMessages;
Panel1.Caption:='MS Word启动完毕,正在更新文档内容......';

ItemIndex :=1;
WordDocument1.ConnectTo(WordApplication1.Documents.Item(ItemIndex));
//查找并用数据库的内容替换
//更新语句省略

WordDocument1.Range.Find.Execute( FindText, MatchCase, MatchWholeWord,
MatchWildcards, MatchSoundsLike, MatchAllWordForms, TForward,
Wrap, TFormat, ReplaceWith, Replace );

Application.ProcessMessages;
Panel1.Caption:='MS Word正在打印文档内容......';
WordDocument1.PrintOut;
Application.ProcessMessages;
//这里如何判断打印完毕可以退出word了?????
Panel1.Caption:='MS Word正在退出......';

SaveChanges := WdDoNotSaveChanges; //为了不出线保存提示,用了WdDoNotSaveChanges
OriginalFormat := UnAssigned;
RouteDocument := UnAssigned;

finally
WordDocument1.Disconnect;
WordApplication1.Quit(SaveChanges, OriginalFormat, RouteDocument);
WordApplication1.Disconnect;
Panel1.Visible:=False;
end;
end;
 
你只使用了无参数的PrintOut,试试用下面的函数(Word VBA帮助中有)
WordDocument1.PrintOut(Background, Append, Range, OutputFileName,
From, To, Item, Copies, Pages, PageType, PrintToFile,
Collate, FileName, ActivePrinterMacGX, ManualDuplexPrint,
PrintZoomColumn, PrintZoomRow, PrintZoomPaperWidth, PrintZoomPaperHeight)

[blue]Background 如果此参数为 True,则 Microsoft Word 在打印文档的同时继续运行宏。[/blue]



 
ffsquell:帮助没有装.而且我希望是打印完后word退出

WordDocument1.PrintOut;
//我想这里应该有个循环来检测状态吧,如果在打印就等待什么的.
//这个当前状态怎么检测呢.比如在打印中,就绪什么的.
SaveChanges := WdDoNotSaveChanges; //为了不出线保存提示,用了WdDoNotSaveChanges
WordDocument1.Disconnect;
WordApplication1.Quit(SaveChanges, OriginalFormat, RouteDocument);
WordApplication1.Disconnect;
 
试试 WordApplication.BackgroundPrintingStatus 属性
(返回后台打印队列中的打印任务数目。)

begin
while WordApplication.BackgroundPrintingStatus>0 do//未打印完
begin
/*
建议不要用循环,这样会造成程序等待,可用线程,
或者干脆直接提示“正在打印”对话框!
*/
end;
end.
 
接受答案了.
 
后退
顶部