• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

How do you run a PDF file from Visual Basic?

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.
1 Solution
Chris BottomleySoftware Quality Lead EngineerCommented:
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now