Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PowerView Button Missing From Excel 2013 Pro Plus Insert Tab 7 1,108
Surface Book vs Surface Pro 4 56
Select tabs in Word with Powershell 8 43
MS Word Office 365 Mail Merge 2 51
Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
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…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

895 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