Hi all,
i use the following code to locate PDF's and print them.
This works great, however it goes to the default printer. Is there a way to specify which printer to use?
I cannot simply just change the default printer as some documents that i print on here have to go to the current default printer. So preferably i need to be able to set the printer to use in the code.
Thanks
i use the following code to locate PDF's and print them.
VBA Code:
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 PrintReceiverCert()
Dim strPath As String
Dim WorksOrder As String
'Get user entered WorksOrder Number
WorksOrder = frmForm.TextBox27.Value
If Len(WorksOrder) > 0 Then
With Sheets("Database")
myMatch = Application.Match(WorksOrder, .Columns(4), 0)
If IsNumeric(myMatch) Then
MsgBox "Certificate Found"
strPath = "T:\pe_projects\Engineering\Receiver Mounted Stationary Screw Compressors\9_RM Database\Receiever Certs\" & .Cells(myMatch, 19)
Else
MsgBox "Works Order Number not found"
End If
End With
End If
If Not PrintPDF(0, strPath) Then
MsgBox "Printing failed"
End If
End Sub
This works great, however it goes to the default printer. Is there a way to specify which printer to use?
I cannot simply just change the default printer as some documents that i print on here have to go to the current default printer. So preferably i need to be able to set the printer to use in the code.
Thanks