Share via

Visual Basic Command button on a Form to Open a pdf file

Anonymous
2012-08-21T16:55:16+00:00

Hi,

Is it possible to run a macro or procedure from a Command Button on a Form to open a .pdf file in Acrobat?

.... Or maybe a Hyperlink from a command button to open the pdf?

I can't find much on this in the Help section.

Thanks for your time in advance,

Amy

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-08-21T18:57:24+00:00

At the top of the code module, before and above any procedure, use the following Declare:

Private Declare Function FindExecutable _

    Lib "shell32.dll" Alias "FindExecutableA" ( _

    ByVal lpFile As String, ByVal lpDirectory As String, _

    ByVal lpResult As String) As Long

Then, use the following procedure:

Sub OpenPDF()

    Dim ExeName As String

    Dim FileName As String

    Dim N As Long

    ExeName = String(260, 0)

    FileName = "G:\Reference Documents\HP 16.pdf" '<<< CHANGE

    N = FindExecutable(FileName, vbNullString, ExeName)

    ExeName = Left(ExeName, InStr(1, ExeName, vbNullChar) - 1)

    Shell ExeName & " " & Chr(34) & FileName & Chr(34), vbNormalFocus

End Sub

Change the line marked with <<< to the appropriate PDF file name.

Was this answer helpful?

3 people found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful