Results 1 to 3 of 3

Thread: How to launch Adobe PDF file from Excel

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Location
    England
    Posts
    21

    How to launch Adobe PDF file from Excel

    Please can anyone show me how to code a macro in Excel to launch a pdf file. As it will be installed on lots of PC's I do not want to have to specify the path to adobe exe file, just the pdf (which I will know the path to).

    I have tried
    Code:
    Task_Manual = ShellExecute(Me.hwnd, vbNullString, ActiveWorkbook.Path & "\CT38 - SHS Joint Software Manual.pdf", vbNullString, "C:\", SW_SHOWNORMAL)

    but get 'Invalid use of Me keyword' error message.

    I am still learning VB so an example of code would be most helpful.

    Many thanks

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: How to launch Adobe PDF file from Excel

    You can use the handle of the Excel.application object for this:

    VB Code:
    1. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
    2. (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
    3. ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    4.  
    5. Private Const lngSW_SHOWNORMAL As Long = 1
    6.  
    7. Private Sub CommandButton1_Click()
    8.     ShellExecute Excel.Application.hwnd, vbNullString, "http://www.google.com", vbNullString, "C:\", lngSW_SHOWNORMAL
    9. End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Location
    England
    Posts
    21

    Re: How to launch Adobe PDF file from Excel

    Thanks Alex, it works a treat, very much appreciated.

    Chris

Posting Permissions

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



Click Here to Expand Forum to Full Width