Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr
Const SW_HIDE as long = 0&
Sub PrintPDF(strFile as string)
ShellExecute Application.hWnd, "Print", strFile, 0&, 0&, SW_HIDE
End Sub
Option Explicit
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 PrintThisDoc(formname As Long, FileName As String)
On Error Resume Next
Dim X As Long
X = ShellExecute(formname, "Print", FileName, 0&, 0&, 3)
End Function
Sub testPrint()
Dim printThis
Dim strDir As String
Dim strFile As String
strDir = "P:\17. PPI Packs\1. BARC001- BARCLAYS\PPIBARC001-002"
strFile = "GTA-000018-009_2013-01-08_0223.pdf"
printThis = PrintThisDoc(0, strDir & strFile)
End Sub
Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr
Const SW_HIDE as long = 0&
Sub PrintPDF(strFile as string)
ShellExecute Application.hWnd, "Print", strFile, 0&, 0&, SW_HIDE
End Sub
Sub testPrint()
Dim strDir As String
Dim strFile As String
strDir = "P:\17. PPI Packs\1. BARC001- BARCLAYS\PPIBARC001-002\"
strFile = "GTA-000018-009_2013-01-08_0223.pdf"
PrintPDF strDir & strFile
End Sub
The complete code would be:
Code:Declare PtrSafe Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr Const SW_HIDE as long = 0& Sub PrintPDF(strFile as string) ShellExecute Application.hWnd, "Print", strFile, 0&, 0&, SW_HIDE End Sub Sub testPrint() Dim strDir As String Dim strFile As String strDir = "P:\17. PPI Packs\1. BARC001- BARCLAYS\PPIBARC001-002\" strFile = "GTA-000018-009_2013-01-08_0223.pdf" PrintPDF strDir & strFile End Sub
Note that I added a backslash to the end of your folder path.
Compile Error:
Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules