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.
<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: