Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Sep 2007
    Posts
    54
    Thanks
    7
    Thanked 1 Time in 1 Post

    VBA - Printing a picture using OIS.exe without the print dialog box

    Hi there.

    I'm hoping someone can help me. I currently have a vba macro in Excel that looks in Column "A" and picks out all paths of documents with an ending of ".pdf" and prints the document using the default pdf reader. I would like to expand this macro so that it prints .jpg, .tiff and .tifflist pictures to either the Microsoft Picture Manager or the Windows Photo Viewer, except that I end up getting the print dialog box, which I don't want. I tried searching the internet, but couldn't seem to find a way to resolve this. I can't use Paint because there are multi-page Tiff files that will only print the first page in the Tiff file.

    Has anyone accomplished this? I will include the code that I have so far and cross my fingers that it is something really easy...

    Code:
     Option Explicit
          Private Declare Function ShellExecute Lib "shell32.dll" Alias _
          "ShellExecuteA" (ByVal hwnd As Long, ByVal lpszOp As _
          String, ByVal lpszFile As String, ByVal lpszParams As String, _
          ByVal lpszDir As String, ByVal FsShowCmd As Long) As Long
          Private Declare Function GetDesktopWindow Lib "user32" () As Long
         
          Const SW_SHOWNORMAL = 1
          Const SE_ERR_FNF = 2&
          Const SE_ERR_PNF = 3&
          Const SE_ERR_ACCESSDENIED = 5&
          Const SE_ERR_OOM = 8&
          Const SE_ERR_DLLNOTFOUND = 32&
          Const SE_ERR_SHARE = 26&
          Const SE_ERR_ASSOCINCOMPLETE = 27&
          Const SE_ERR_DDETIMEOUT = 28&
          Const SE_ERR_DDEFAIL = 29&
          Const SE_ERR_DDEBUSY = 30&
          Const SE_ERR_NOASSOC = 31&
          Const ERROR_BAD_FORMAT = 11&
       Private Declare Function GetRidofDialog Lib "    " ()
    Function StartDoc(DocName As Variant) As Long
              Dim Scr_hDC As Long
              Scr_hDC = GetDesktopWindow()
              StartDoc = ShellExecute(Scr_hDC, "Print", DocName, _
              "", "C:\", SW_SHOWNORMAL)
              
    End Function
    
      
    Sub PrintPDFfiles()
    
    Dim zProg As String
    Dim SayWhat, Btns, BoxTitle, Answer, cell
    Dim zLastRow As Long, Temp As String
    Dim zFile As Variant, zDone As Long
    Dim zCommand As Long
    'FETCH NUMBER OF FILES TO PRINT..
    zLastRow = [a65536].End(xlUp).Row           'find last row in column [A]; e.g. 15
    Temp = "a1:a" & zLastRow                    'e.g. "a1:a15"
    'DISPLAY MESSAGE BEFORE PROCEEDING..
    SayWhat = "Did you set a Zerox printer as your default printer?"   'message text
    Btns = vbYesNoCancel + vbDefaultButton2     'message box buttons
    BoxTitle = "PRINT PDF FILES.."              'message box heading
    Answer = MsgBox(SayWhat, Btns, BoxTitle)    'display message box
    'CHECK IF USER WANTS TO PROCEED..
    If Answer <> vbYes Then                     'User cancelled; did not click [Yes] button
    Exit Sub                                    'nothing else to do
    End If                                      'end of test for User cancelled
    'PROCEED WITH PRINTING PDF FILES..
    For Each cell In Range(Temp)                'loop through all entries in COLUMN [A] range
    zFile = Trim(cell.Value)                    'fetch filename from cell; remove any trailing spaces
    zDone = 0                                   'initialise counter
    If zFile Like "*.pdf" Then                  'make sure it is a pdf file type
        
    zCommand = StartDoc(zFile)
    ElseIf zFile Like "*.jpg" Then
        zCommand = StartDoc(zFile)
    ElseIf zFile Like "*.tiff" Then
        zCommand = StartDoc(zFile)
    ElseIf zFile Like "*.tifflist" Then
        zCommand = StartDoc(zFile)
    zDone = zDone + 1                           'increment counter
    End If                                      'end of test for pdf file type
    Application.Wait (Now + TimeValue("0:00:05"))
    Next                                        'process next file in list
    'DISPLAY COMPLETION MESSAGE..
    SayWhat = "DONE!"
    SayWhat = SayWhat & vbCr & vbCr
    SayWhat = SayWhat & "Your files are being sent to default printer. This make take a few minutes"
    SayWhat = SayWhat & vbCr & vbCr
    Btns = vbOKOnly + vbInformation
    BoxTitle = "PRINTING ROUTINE"
    Answer = MsgBox(SayWhat, Btns, BoxTitle)
    End Sub

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,853
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Can the command lines in the following thread be adapted to work on your machine?
    http://stackoverflow.com/questions/1...g-in-windows-7
    http://stackoverflow.com/questions/1...ba-if-not-what

    If you can work out a command line that works it should be easy enough to code into your macro.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    Star Lounger
    Join Date
    Sep 2007
    Posts
    54
    Thanks
    7
    Thanked 1 Time in 1 Post
    Thanks for your response Andrew! Unfortunately, with either one of the command lines, I still get the print dialog box. Is there any way to send the picture to print without getting the box?

    I have tried:
    Shell ("rundll32.exe & C:\Windows\System32\shimgvw.dll, ImageView_PrintTo /pt" & DocName) - but nothing prints
    PrintPicture = Shell("cmd /c (Program Files (x86)\Microsoft Office\Office14\OIS.exe) /p " & DocName) - but nothing prints
    DocName = ShellExecute(0&, "Print", DocName, 0&, 0&, SW_SHOWNORMAL) - but I get the pop-up box below
    Set PrintPicture = CreateObject("Shell.Application")
    PrintPicture.ShellExecute "rundll32.EXE c:\Windows\System32\Simgvw.dll", DocName, "", "print", 0 - but I just get an error.

    I may just be struggling with syntax. Can anyone help guide me in the right direction, please?


    Capture.PNG
    Last edited by maverik; 2015-09-24 at 11:39.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •