Link to home
Start Free TrialLog in
Avatar of Chris_Kirkcaldy
Chris_Kirkcaldy

asked on

Printing from Excel to PDF - multiple PDF jobs?

Hi, using a list of data I am creating singular spreadsheets for each row, and then once each spreadsheet has been created, I am wanting to print the data to PDF (without displaying the PDF file on screen), closing the individual excel file, and then looping to do the exact same process for all other rows on screen.

Unfortunately though for some files pdfFactory Pro opens on screen, and as soon as this happens, once the macro attempts to create the next PDF file, since the previous PDF is still open on screen, the jobs are just added on top of each other and the PDF files aren't created - ANY IDEAS?? This is driving me nuts!!

The PDF code I am using is as follows:

Public Sub Generate_PDF_File()
Dim PDF_FileName As String
Dim lpNewVal, i As Long
Dim PrintOut As Boolean
Dim ch As Characters
Dim UsedPrinter As String

     If RegOpenKeyEx(HKEY_CURRENT_USER, "Software\FinePrint Software\pdfFactory2\FinePrinters\,,michprn01,pdfFactory\PrinterDriverData", 0&, KEY_QUERY_VALUE + KEY_SET_VALUE, hKey) = ERROR_SUCCESS And _
       RegOpenKeyEx(HKEY_CURRENT_USER, "Software\FinePrint Software\pdfFactory2", 0&, KEY_QUERY_VALUE + KEY_SET_VALUE, hKey2) = ERROR_SUCCESS Then
   
        i = RegQueryValueEx(hKey, "ShowDlg", ByVal 0&, lpType, lpData, lpLen)        'dummy to initialize
         If RegQueryValueEx(hKey, "ShowDlg", ByVal 0&, lpType, lpData, lpLen) = ERROR_SUCCESS Then
            lpNewVal = 4                               '1 view UI, 4 no UI, no e-mail, no view pdf
           
                If IntermediaryType = "" Then PDF_FileName = "J:\Trail\IRIC\Investor IRIC Confirmations\IRIC Confirmation " & TheYear & "." & TheMonth & "." & TheDay & " " & InvestorID & " " & Gaining_Int_PCID & ".pdf"
                If IntermediaryType = "Losing" Then PDF_FileName = "J:\Trail\IRIC\Losing Intermediary IRIC Confirmations\IRIC Confirmation " & TheYear & "." & TheMonth & "." & TheDay & " " & IntermediaryPCID & ".pdf"
                If IntermediaryType = "Gaining" Then PDF_FileName = "J:\Trail\IRIC\Gaining Intermediary IRIC Confirmations\IRIC Confirmation " & TheYear & "." & TheMonth & "." & TheDay & " " & IntermediaryPCID & ".pdf"
           
            'change settings
            RegSetValueEx_DWord hKey, "ShowDlg", 0&, REG_DWORD, lpNewVal, 4
            RegSetValueEx_String hKey2, "OutputFile", 0&, REG_SZ, PDF_FileName, Len(PDF_FileName)
           
                PrintOut = Worksheets("Sheet1").PrintOut(copies:=1, preview:=False, ActivePrinter:="\\michprn01\pdfFactory", PrintToFile:=False, Collate:=True, PrToFileName:=PDF_FileName)    'Print worksheet to PDF
               
                'MySheet.Range("MyRange").PrintOut copies:=1, preview:=False, ActivePrinter:="Adobe PDF", PrintToFile:=False, Collate:=True, PrToFileName:=PDFFileName
               
                If IntermediaryType = "" Then Application.Wait (Now + TimeValue("0:00:03"))   'Apply Waiting Time
                If IntermediaryType = "Losing" Then Application.Wait (Now + TimeValue("0:00:06"))   'Apply Waiting Time
                If IntermediaryType = "Gaining" Then Application.Wait (Now + TimeValue("0:00:06"))   'Apply Waiting Time
               
            lpNewVal = 1
            RegSetValueEx_DWord hKey, "ShowDlg", 0&, REG_DWORD, lpNewVal, 4

        Else
            ch = MsgBox("No PDF Printer found !", vbOKCancel, "Error")
        End If
        RegCloseKey hKey
        Else
            ch = MsgBox("No PDF Printer found !", vbOKCancel, "Error")
        End If

End Sub
Avatar of Richard Daneke
Richard Daneke
Flag of United States of America image

Please specifiy your Excel version and PDF features vary greatly.
Avatar of Chris_Kirkcaldy
Chris_Kirkcaldy

ASKER

Thanks for the helpful comment!
Sorry, there was a typo.  It should have read:
Please specifiy your Excel version as PDF features vary greatly.
In 2003 versions and earlier, many people used a third party app for PDF creation.  Some installed the standard Adobe for PDF creation.  
In 2007 (and 2010), a Microsoft add-in makes PDF creation easy with an OutputTo option.   I was not being glib.  I was trying to better understand your technical environment.
Hi DoDadD,
I'm using Excel 2003, and PDF Factory Pro. Does this help?
Thanks,
Chris
Looking at the code, why is PrintToFile FALSE? If you make this TRUE will the dialog box not open?
PrintOut = Worksheets("Sheet1").PrintOut(copies:=1, preview:=False, ActivePrinter:="\\michprn01\pdfFactory", PrintToFile:=False, Collate:=True, PrToFileName:=PDF_FileName) 'Print worksheet to PDF

'MySheet.Range("MyRange").PrintOut copies:=1, preview:=False, ActivePrinter:="Adobe PDF", PrintToFile:=False, Collate:=True, PrToFileName:=PDFFileName
Also, PDFFactory has a dialog box option:
Open the pdfFactory Printing Preferences (right-click the pdfFactory icon)and turn off the dialog box display.
Sorry DoDahD, someone else had responded to my question with "I don't know", hence my "Thanks for the helpful comment!" message - this wasn't directed at you!!
Yes, I had tried both PrintToFile = False and True, but on both I received the same message :-(  I'll give the printing preferences a go and get back to you shortly...
Hi DoDahD,
I've tried playing around with the pdfFactory Pro dialog settings - when ticking the "Do not show dialog" box this enables 4 options. Selecting the "save the file in the AutoSave folder" doesn't work (gives me the same pop-up PDF window), and I'm not sure which of the other options to select - any ideas?
I also have the option to have Nitro PDF to be installed onto my computer instead of PDF Factory Pro - do you know if this would make any difference.
Many thanks
No, I am maxed out on ideas.   Others are welcome to opine.
No worries, thanks anyway
DoDahD you mentioned excel 2007 having an extra OutputTo option - if I were to utilise Excel 2007 could this problem be overcome? Happy trying anything...
ASKER CERTIFIED SOLUTION
Avatar of Richard Daneke
Richard Daneke
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial