locked
Printing graphic file RRS feed

  • Question

  •  

    Hello,

    I have small question about printing graphic file. How send to printer picture ( graphic file) under VBA?

    Monday, April 10, 2006 1:06 PM

Answers

  • Hi, you can try calling the Windows API, like this...

    Private 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 Sub PrintImage()
        ShellExecute Application.hwnd, "print", "C:\image1.bmp", vbNullString, "C:\", 0
    End Sub

    Unfortunately on my machine it only opened the image rather than print it. You could try importing the image into a temporary document/slide/sheet/whatever and print it through the VBA host.

        ActiveSheet.Pictures.Insert("C:\17.jpg").Select
        ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

    You can of course change the ActiveSheet to a hidden temp sheet that you delete once you finish.

    Monday, April 10, 2006 3:14 PM