Ho do I launch a pdf file from Excel?

C

Chris_M

As a newbie does anyone have some sample code I can modify. As it will be
used on different PC's I will not be able to define the path to acrobat.exe
but will know the path to the pdf I want to launch.

I have tried shell but it only seems to be for exe files.

Thanks
 
J

Jonathan West

Chris_M said:
As a newbie does anyone have some sample code I can modify. As it will be
used on different PC's I will not be able to define the path to
acrobat.exe
but will know the path to the pdf I want to launch.

I have tried shell but it only seems to be for exe files.

Thanks

Paste the following into a separate module

Option Explicit

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


Public Function OpenDoc(ByVal DocFile As String) As Long
OpenDoc = ShellExecute(0&, "open", DocFile, vbNullString, vbNullString,
vbNormalFocus)
End Function


If you pass a full pathname to the OpenDoc function, it will open the file
using its default application, whatever that might be.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
C

Chris_M

Thanks Jonathan, works brill. tho' not sure waht it all means, have looked up
ShellExecute but don't understand the 0&, what does it mean?
 
J

Jonathan West

Chris_M said:
Thanks Jonathan, works brill. tho' not sure waht it all means, have looked
up
ShellExecute but don't understand the 0&, what does it mean?

0& means zero passed as a Long. The window handle has to be passed as a
Long, and you can simply use zero as the value in this context.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
Top