Forum Discussion
How to print an image file directly
Good afternoon
From the research I've been doing, I've already realized that what I want can't be achieved with Excel, without having to program the printing manually, which I'm not able to do.
I found this code that was supposed to open the file and the windows window, to print, but I can't make the window open. O que estarei a fazer errado?
It's not the ideal solution, because there are a lot of files to print, but it's better than nothing.
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 teste()
Dim hwnd
Dim StartDoc
hwnd = apiFindWindow("OPUSAPP", "0")
Dim mypath As String, myfile As String, strFilePath As String
mypath = "C:\Users\LRMud\TESTE\09 - TI'S - General\GESTAO DESPESAS\21PT00\Ana\"
myfile = Dir(mypath & "2021119_21PT00_Ana_2_01.jpg")
strFilePath = mypath & myfile
StartDoc = ShellExecute(hwnd, "Print", strFilePath, "", "", SW_SHOWNORMAL)
End Sub