mehidy1437
Active Member
- Joined
- Nov 15, 2019
- Messages
- 348
- Office Version
- 365
- 2016
- 2013
- Platform
- Windows
- Mobile
- Web
Hi, I'm using the below code to print files to a different printer than the default printer.
But my file is always printing to the default printer, but not to the application.activeprinter
Please help me to sort out the issue.
But my file is always printing to the default printer, but not to the application.activeprinter
Please help me to sort out the issue.
VBA Code:
Declare PtrSafe 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
Declare PtrSafe Function apiFindWindow Lib "User32" Alias "FindWindowA" _
(ByVal lpclassname As Any, ByVal lpCaption As Any) As Long
Global Const SW_SHOWNORMAL = 1
Sub ShellExecuteExample()
''''''''''''''''''''''''''''''''''''''''
''https://support.microsoft.com/en-us/topic/wd2000-how-to-call-the-shellexecute-windows-api-function-80da207b-2fa3-ac60-e871-f0a63164bad7
'''''''''''''''''''''''''''''''''''''''
Dim hwnd
Dim StartDoc
hwnd = apiFindWindow("OPUSAPP", "0")
Dim mypath As String, myfile As String, strFilePath As String
mypath = "C:\Users\User\Desktop\test\"
myfile = Dir(mypath & "*.ai*")
Dim my_printer As String, chkActivPrinter As String, chkDefultPrinter As String
my_printer = Application.ActivePrinter
Application.ActivePrinter = "PDFill PDF&Image Writer on Ne05:"
chkActivPrinter = Application.ActivePrinter
Do While myfile <> ""
strFilePath = mypath & myfile
StartDoc = ShellExecute(hwnd, "Print", strFilePath, "", "", SW_SHOWNORMAL)
'Application.Wait Now + TimeValue("00:00:07")
myfile = Dir
Loop
Application.ActivePrinter = my_printer
chkDefultPrinter = Application.ActivePrinter
End Sub