Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Sending a PDF file to print (2003)

    Is there a way to pass in a filename and send a document (PDF) to the default printer (or a specified printer) using VBA?

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Sending a PDF file to print (2003)

    Yes, by using ShellExecute.

    Copy the following code into a standard module, at the top (above other Subs and Functions):
    <code>
    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

    Private Const SW_SHOWNORMAL = 1

    Public Sub PrintFile(FileName As String)
    Dim lngResult As Long
    lngResult = ShellExecute(0&, "Print", FileName, 0&, 0&, SW_SHOWNORMAL)
    If lngResult <= 32 Then
    MsgBox "Something went wrong.", vbExclamation
    End If
    End Sub
    </code>
    You can use this as follows to print a PDF file:
    <code>
    Call PrintFile("CocsMyDocument.pdf")
    </code>
    It works with other file types too.

    Note: you should copy the code from the Lounge, not from the e-mail notification if you receive that - the code will probably be mangled there.

  4. #3
    3 Star Lounger
    Join Date
    Aug 2002
    Location
    Brisbane, Queensland, Australia
    Posts
    387
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Sending a PDF file to print (2003)

    Thanks Hans, that does it.

Posting Permissions

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