Open file explorer then open pdf via command button.

erutherford

Active Member
Joined
Dec 19, 2016
Messages
458
Search for an hour. I didn't think it would be that hard but guess what! The last line is the problem or at least I think it is.

VBA Code:
Private Sub CommandButton9_Click() 'Print "Read me first pdf"

Dim sFile As String
Open_file = Application.GetOpenFilename(Title:="Browse & Select File", FileFilter:="All PDF Files (*.pdf*), *.pdf*")
PDF.Open sFile, vbNormalFocus

End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try this:

VBA Code:
Private Sub CommandButton9_Click()

    Dim file As Variant
    Dim Sh As Object
    
    file = Application.GetOpenFilename(Title:="Browse & Select File", FileFilter:="All PDF Files (*.pdf*), *.pdf*")

    If file <> False Then
        Set Sh = CreateObject("Shell.Application")
        Sh.ShellExecute file, "", "", "open", 1
    End If

End Sub
 
Upvote 0
Hi ertherford. You can trial this. HTH. Dave
VBA Code:
Private Sub CommandButton1_Click()
Dim sFile As String, myShell As Object
Set myShell = CreateObject("WScript.Shell")
sFile = Application.GetOpenFilename(Title:="Browse & Select File", FileFilter:="All PDF Files (*.pdf*), *.pdf*")
myShell.Run sFile, vbNormalFocus
End Sub
edit: I see John's already got it right.
 
Upvote 0
I searched for 10 minutes.
ActiveWorkbook.FollowHyperlink Open_File

For pdf's , not necessarily other file types.
EDIT - forgot to mention that I much prefer msoFileDialogs for this.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top