Open file explorer then open pdf via command button.

erutherford

Active Member
Joined
Dec 19, 2016
Messages
453
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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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,221,443
Messages
6,159,907
Members
451,601
Latest member
terrynelson55

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