Solved

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

Posted on 2009-06-27
2
342 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
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…
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.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

690 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