I'm trying to create a macro that will export the sheet to a PDF file using the Bullzip PDF printer. But for some unknown reason, QV keep crashing when I run the macro. It crashes during the printing, and it is random. (not tied to specific sheet)
Below is the macro code I'm using:
vPDFPath = ActiveDocument.GetVariable("vPDFPath").GetContent().String 'QV - Get the PDF save path from the QV variable.
vPrintSheet = "|" & ActiveDocument.GetVariable("vPrintSheet").GetContent().String & "|" 'QV - Get the sheets to print. separated using pipe.
vEmailFrom = ActiveDocument.GetVariable("vEmailFrom").GetContent().String 'QV - Get email from value from the variable.
vEmailTo = ActiveDocument.GetVariable("vEmailTo").GetContent().String 'QV - Get email to value from the variable.
vEmailSubject = ActiveDocument.GetVariable("vEmailSubject").GetContent().String 'QV - Get email subject value from the variable.
vEmailTextBody = ActiveDocument.GetVariable("vEmailTextBody").GetContent().String 'QV - Get email text body value from the variable.
vEmailAttachment = vPDFPath
vPageCount = 1 'QV - for merging the pages in PDF.
for i = 0 to ActiveDocument.NoOfSheets - 1 'Loop through all the sheets in the QVW
set obj = ActiveDocument.GetSheet(i) 'QV - Assign sheet to an object.
vSheetName = obj.GetProperties.Name 'QV - Get the sheet name and assign it to a variable.
If instr(vPrintSheet,"|" & vSheetName & "|") then 'QV - check if the current is in the "printable" list.
ActiveDocument.GetSheet(i).Activate 'QV - Activate the QV sheet.
ActiveDocument.GetApplication.WaitForIdle 'QV - wait for all QV objects loaded.
if vPageCount = 1 then
vMergeFlag = false 'If first page, don't merge.
vMergeFlag = true 'If not first page, then perform merge.
Call PrintPDFWithBullZip(vPDFPath, vMergeFlag) 'Change the printer settings.
I would change the print-function into a sub-routine and also include there the actually print-execution. Further I would increase the sleep-statements maybe to 5000 - if it's working you could decrease them again until it keeps stable.