Hi all
Please help me to correct VBA code to bypass popup screen to manually select location to save print PDF file. Default to specific new folder also possible.
' print pdf to pdf, printer set as Adobe PDF
Public 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
Public Function PrintPDF(xlHwnd As Long, FileName As String) As Boolean
Dim X As Long
On Error Resume Next
X = ShellExecute(xlHwnd, "Print", FileName, 0&, 0&, 3)
If Err.Number > 0 Then
MsgBox Err.Number & ": " & Err.Description
PrintPDF = False
Else
PrintPDF = True
End If
On Error GoTo 0
End Function
Sub PrintSpecificPDF()
'opens the specified pdf and prints it using the default printer
Dim strPth As String, strFile As String
strPth = "C:\PDF\"
strFile = Dir(strPth & "*.pdf")
Do While Len(strFile) > 0
If Right(strFile, 3) = "pdf" Then
If Not PrintPDF(0, strPth & strFile) Then
MsgBox "Printing failed"
End If
End If
strFile = Dir
Loop
End Sub
Thank you in advance.
Adul_C
Please help me to correct VBA code to bypass popup screen to manually select location to save print PDF file. Default to specific new folder also possible.
' print pdf to pdf, printer set as Adobe PDF
Public 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
Public Function PrintPDF(xlHwnd As Long, FileName As String) As Boolean
Dim X As Long
On Error Resume Next
X = ShellExecute(xlHwnd, "Print", FileName, 0&, 0&, 3)
If Err.Number > 0 Then
MsgBox Err.Number & ": " & Err.Description
PrintPDF = False
Else
PrintPDF = True
End If
On Error GoTo 0
End Function
Sub PrintSpecificPDF()
'opens the specified pdf and prints it using the default printer
Dim strPth As String, strFile As String
strPth = "C:\PDF\"
strFile = Dir(strPth & "*.pdf")
Do While Len(strFile) > 0
If Right(strFile, 3) = "pdf" Then
If Not PrintPDF(0, strPth & strFile) Then
MsgBox "Printing failed"
End If
End If
strFile = Dir
Loop
End Sub
Thank you in advance.
Adul_C