How do you run a PDF file  from Visual Basic?

Posted on 2009-12-20
Last Modified: 2012-05-08
I want to run a pdf file from my VB5 program like I do .doc files.  I successfully use,

X = Shell ("write test.doc",1) to open a .doc file


X = Shell("test.pdf",1) does not open the pdf file.
Question by:drleewood
    1 Comment
    LVL 59

    Accepted Solution

    Hello drleewood,

    Add the shellexecute declaration to the top of the code module, (after option statements if present).  The act of opening a file is captured by the call to the sub.


    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
    Sub testOpen()
        ShellExecute 0&, "open", "c:\deleteme\fred.pdf", 0&, 0&, 0&
    End Sub

    Open in new window


    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now