开发者

Any way to determine when Excel background printing has finished?

开发者 https://www.devze.com 2022-12-13 20:48 出处:网络
I\'m using COM in LotusScript (Lotus Notes) to make Excel print several sheets in one workbook to PDFCreator, then make PDFCreator combine then into one PDF.

I'm using COM in LotusScript (Lotus Notes) to make Excel print several sheets in one workbook to PDFCreator, then make PDFCreator combine then into one PDF. The problem is that calling Excel's PrintOut method immediately followed by PDFCreator's cCombineAll meth开发者_高级运维od results in one or more sheets being omitted from the PDF. It seems like Excel's PrintOut method returns before printing is complete.

Putting a Sleep in my code works, but may not be reliable as the printing time varies, so...

Is there any Excel property or method I can call to determine whether printing has finished?

Alternately, is there a way make the PrintOut method block until printing is finished?

I haven't been able to find an answer in Excel's VBA Help.


This sample code from excelguru.ca suggestst you need to use the cCountOfPrintJobs property of PDFCreator to monitor when the job starts and stops printing. Once printing is complete, you can perform whatever other operations you need

Set pdfjob = New PDFCreator.clsPDFCreator

' ...missing out various initialisation steps

'Print the document to PDF
ActiveSheet.PrintOut copies:=1, ActivePrinter:="PDFCreator"

'Wait until the print job has entered the print queue
Do Until pdfjob.cCountOfPrintjobs = 1
    DoEvents
Loop
pdfjob.cPrinterStop = False

'Wait until PDF creator is finished then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
    DoEvents
Loop
pdfjob.cClose


I think the other method is to set the "Background" argument of "PrintOut" to false.

0

精彩评论

暂无评论...
验证码 换一张
取 消