Print PDF

Bocco50

New Member
Joined
Apr 12, 2021
Messages
1
Office Version
  1. 2010
Platform
  1. Windows
This is my first post in MrExcel; I have gratefully referenced it for a few years. I recently borrowed code to print PDF from MrExcel.com, curtesy of starl Administrator. I used debug in VBA to step through the code and it executes as expected. There are no errors presented and seems to terminate as expected. The only problem is the PDF never prints. I know the printer works and the path and file name are correct. I'm sure I am missing something here; would someone be kind enough to take a read and suggest what may be the issue I am on Windows 10; MICROSOFT OFFICE 2016. The code follows:
I start with ...... Call PrintSpecificPDF from a CommandButton.


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
' Code Source MrExcel.com, curticy of starl Administrator

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()
' Code Source MrExcel.com, curticy of starl Administrator

'opens the specified pdf and prints it using the default printer
'note that it uses the default PDF program and leaves it open

Dim strPth As String, strFile As String

strPth = "C:\Users\bocco\OneDrive\Documents\Recipes\Breads\"
strFile = "Popovers.pdf"

If Not PrintPDF(0, strPth & strFile) Then
MsgBox "Printing failed"
End If
MsgBox "Print Should Have Occured"
End Sub


Thanks for your time and consideration.

John
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Watch MrExcel Video

Forum statistics

Threads
1,130,310
Messages
5,641,450
Members
417,210
Latest member
rins

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
Top