Results 1 to 7 of 7
  1. #1
    2 Star Lounger
    Join Date
    Nov 2001
    Location
    Watford, Hertfordshire, England
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Launch pdf from Excel (2000)

    <P ID="edit" class=small>(Edited by HansV on 16-May-03 10:57. Made subject more descriptive)</P>How can I launch a .pdf document from an Excel macro.
    Neil Eustice
    Woody Worshipper

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

    Re: Launch pdf from Excel (2000)

    Put the following declarations at the beginning of a module:

    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 Const SW_SHOWNORMAL = 1
    Public Const SW_SHOWMINIMIZED = 2
    Private Const SW_SHOWMAXIMIZED As Long = 3

    Then, adapt the following macro to your needs:

    Sub ShowPDF()
    Dim lngResult As Long

    lngResult = ShellExecute(0&, "Open", _
    "C:TestSomeFile.pdf", 0&, 0&, SW_SHOWMAXIMIZED)
    If lngResult <= 32 Then
    MsgBox "Something went wrong.", vbExclamation
    End If
    End Sub

  3. #3
    2 Star Lounger
    Join Date
    Nov 2001
    Location
    Watford, Hertfordshire, England
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Launch pdf from Excel (2000)

    Works a treat. Thanks
    Neil Eustice
    Woody Worshipper

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Launch pdf from Excel (2000)

    What is the advantage of using the API ShellExceute instead of VBA's Shell?

  5. #5
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Launch pdf from Excel (2000)

    With the API function you can Open either an application OR a document, and if the latter you specify to simply print the document if that is what you want. This makes things handy for launching the default applications associated with different file types. You would not need to know for example what application a user might use for editing bitmaps. ShellExecute looks after all that.

    Also with ShellExecute you can also specify how the application will be shown, i.e. window state etc.

    Andrew C

  6. #6
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Launch pdf from Excel (2000)

    Shell also allows the window state to be specified.

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Launch pdf from Excel (2000)

    Another advantage of ShellExecute is that it can be used to print a document in the application associated with it, without having to specify the application. Just replace "Open" in the call to ShellExecute by "Print". For folders, ShellExecute also supports "Explore" as action.

Posting Permissions

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