ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Showing a .PDF From Excel Button Using VBA (https://www.excelbanter.com/excel-programming/290872-showing-pdf-excel-button-using-vba.html)

Joey[_3_]

Showing a .PDF From Excel Button Using VBA
 
I have an Excel form that when a user clicks a button, I want to open up a particular .PDF file on the screen
Can anyone show me the code necessary to do this?
TIA

heidi

Showing a .PDF From Excel Button Using VBA
 
did you ever get any responses to this? i am trying to do the very same, seemingly very simple, procedure, and am getting nowhere!

thanks
heid

----- Joey wrote: ----

I have an Excel form that when a user clicks a button, I want to open up a particular .PDF file on the screen
Can anyone show me the code necessary to do this?
TIA

Jake Marx[_3_]

Showing a .PDF From Excel Button Using VBA
 
Hi Joey,

You can use the ShellExecute API function for this. Basically, when used
with the "open" verb, ShellExecute will open the specified file with its
default application. Here's the code needed to do it:

Private Const SW_SHOWMAXIMIZED = 3

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 gbOpenFile(rsPath As String) As Boolean
If ShellExecute(0, "open", rsPath & vbNullChar, _
vbNullString, vbNullString, SW_SHOWMAXIMIZED) 32 Then
gbOpenFile = True
End If
End Function


There are other SW_* constants that determine how the window is displayed.
There are lots of return value constants that can help you trap runtime
errors (instead of just checking for 32), too - just look for shellexecute
on MSDN for more info on them.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Joey wrote:
I have an Excel form that when a user clicks a button, I want to open
up a particular .PDF file on the screen. Can anyone show me the code
necessary to do this??
TIA




All times are GMT +1. The time now is 11:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com