VBA to print PDFs

rdw72777

Well-known Member
Joined
Apr 5, 2005
Messages
723
So I had some macro code (provided by others from here and other sites) that looped through and printed many files that up until today worked just fine:

<code>Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long</code>

and

<code>Public Sub PrintFile(ByVal strPathAndFilename As String)
Call ShellExecute(Application.hwnd, "print", strPathAndFilename, vbNullString, vbNullString, 0)
End Sub</code>

However today it stopped working for PDF files, or more explicitly it prints the first PDF file I loop through but not any subsequent PDF files. All Excel printing works just fine. I've stepped through the code and as the code prints the PDF files if I close the instance of Acrobat Reader that opens upon printings the subsequent PDF printout prints just fine. So I've got some sort of issue with the code hanging on to the instance of Acrobat reader that is opened and would love to find a way to close it. Note that all I'm passing trhoguh my code i s the file path and I'm not instantiating any objects of Acrobat Reader directly...the "Print File" code is what opens Acrobat Reader.

I'm guessing it's an easy fix to close Acrobat Reader after it prints a PDF but I simply can't figure it out.
 
Last edited:

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top