Forum Discussion

csoares's avatar
csoares
Brass Contributor
Nov 10, 2021

How to print an image file directly

Good Morning
I wanted to ask two things:
1st - With excel, I need to open a JPG file that is on my disk and print that file directly, without opening any external program or window asking the user to ask questions.
If excel has to open some application, at least don't question the user and open and close the program automatically.

2nd - When printing the image file, (which is a photo of a document in A4), it is possible to place a footer text on the same page as the image
?
Is it possible to do this procedure? How can I do it?
Thank you for your help.

  • csoares's avatar
    csoares
    Brass Contributor

    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

Resources