Solved

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

Posted on 2009-06-27
2
339 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
All doc, xls, and pdf's are gone 9 92
Word - Access 3 64
Word 2016 - Comments on one page contracted 2 57
word 2016 spell check 3 15
Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

860 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