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. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 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.

  3. #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
  •