You are here:

Business Software/Opening a PDF file from a command button

Advertisement


Question
Hi Todd
I have Excel 2003 and I am wanting to open a .pdf file using a command button. I have found that
   Shell ("C:\Program Files\Adobe\Acrobat 7.0\Acrobat\acrobat.exe C:\Program Files\PERFORM\instuctions.pdf"), 3
Works ok. But the problem I have is that the command to find acrobat.exe is too specific. I tried to copy the acrobat.exe into the same file as the speardsheet but it refused to open it. I don't want to have to rewrite the VB every time I change the version of Acrobat. Is there a way round this problem.
Regards
Eric

Answer
This took a little research and experimentation.  I found this helpful info at: http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnarvb4/html/ms...

I will simplify for you.

The "obvious" solution is to use the fact that the pdf file extension is associated in windows explorer with the current version of acrobat installed.  Thus we can use that if we have the following code calling functions from the shell32.dll in your excel vba module:

'This declaration must be at the top

Private 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

'This code can be anywhere, probably in the same module
Public Sub OpenThisDoc(FileName As String)
   On Error Resume Next
   Dim X As Long
   X = ShellExecute(FormName, "Open", FileName, 0&, 0&, SW_SHOWMAXIMIZED)
End Sub

'this is the one you would run
Sub Run_me()

   OpenThisDoc FileName:="c:\a.pdf"  'put the path and filename to your pdf file

End Sub


Let me know how this works for you.

Business Software

All Answers


Answers by Expert:


Ask Experts

Volunteer


Todd Binenstock

Expertise

I am a technical expert at using Hyperion Essbase to implement solutions for Business Reporting, Planning and Analysis. This is also known as OLAP and Performance Managment Reporting. I also am an expert in Microsoft Excel

Experience

Over 12 years hands-on with Essbase and Excel designing and implementing solutions.

Organizations
Performance Management

Education/Credentials
BS Econonmics and BS Business Administration (Finance and Logistics & Operations Management)

Awards and Honors
Hyperion Certified Professional

Past/Present clients
Sprint, Ralston Purina, Catepillar, Express-Scripts, Bosch Automotive, etc. etc.

©2012 About.com, a part of The New York Times Company. All rights reserved.