Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
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.

705 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

16 Experts available now in Live!

Get 1:1 Help Now