Solved

How can I write VBA code which is the equivalent to manually double clicking a .pdf file?

Posted on 2009-06-27
2
340 Views
Last Modified: 2012-05-07
I would like to display a .pdf file from VBA code.  The first line of the code below does this.

The VBA code will run on multiple computers which will have various versions of Acrobat and AcroRd32 (the free .pdf reader) installed on them.  Manually double clicking on the file "Test.pdf" will display the file no matter what version of Acrobat or the Reader is installed because the .pdf extension determines the correct program to use.

My question is: what is the VBA code to display the "Test.pdf" file on all such computers?  I want the .pdf extension to tell the computer what program to use rather than specify it in the Shell statement.  The second line of code doesn't work.
Shell "C:\Program Files\Adobe\Acrobat 9.0\Acrobat\Acrobat.exe C:\Test.pdf", vbNormalFocus
 
Shell "C:\Test.pdf", vbNormalFocus

Open in new window

0
Comment
Question by:TimLitle
2 Comments
 
LVL 4

Accepted Solution

by:
RapidDelp earned 500 total points
ID: 24729514
I did a search in EE for "windows vba filetype"
And found the link http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_20506943.html?sfQueryTermInfo=1+filetyp+vba+window 

They suggest:

Paste this line into a new module:
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

You can then open a file by using (in a form):
ShellExecute Me.hwnd, "open", strFile, Chr$(0), strPath, 3

If you want to run it from a module, just change Me.hwnd to any open form's hwnd.
0
 

Author Closing Comment

by:TimLitle
ID: 31597586
Thanks -- this was exactly what I was looking for.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

685 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