Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a PDF file from VBA code 3

Status
Not open for further replies.

Sashanan2

Programmer
Jul 2, 2004
39
NL
I'm trying to open a PDF file (path and filename supplied through a string) from VBA code. I've played around with two solutions so far that both don't really do what I want:

1. Using Shell:

Shell ("C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe " & strFileName)

This works fine on my own system but since it relies on Acrobat Reader 7.0 specifically and it being installed in its default folder, this is not going to be reliable enough for my customers. I'd want Windows to decide for itself what to use to open the .pdf with, same way as if you'd double click it in an Explorer window.

Then after searching this forum for a bit I came up with:

2. Using the FollowHyperLink method:

FollowHyperLink strFileName

Unfortunately, when I do this, I see the Acrobat Reader window flash by; it pops up then immediately closes again. The exact same approach works fine if I try it on a .txt or a .doc, for instance (opening them in Notepad and Word respectively) but apparently Acrobat doesn't like it.

Is there something else I could try here? Anything that will just simulate doubleclicking the file in question in Explorer - letting Windows determine what PDFs should be opened with - would work fine.


"Any fool can defend his or her mistakes; and most fools do." -- Dale Carnegie
 
Found a working solution at:


But I'm still open to suggestions for easier approaches (from what I could tell by Googling though, I'm not the first to run into this problem with FollowHyperLink and Acrobat specifically).

"Any fool can defend his or her mistakes; and most fools do." -- Dale Carnegie
 
you may try this:
CreateObject("WScript.Shell").Run Chr(34) & strFileName & Chr(34)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Works fine as well and is certainly a lot less code. Thanks!

"Any fool can defend his or her mistakes; and most fools do." -- Dale Carnegie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top