Open a PDF file with a Combo Box Result

  • Hello,


    I am needing to add a function to my userform to open a PDF file via the results of a combo box. What I have is a combo box that are dependent on the first. The result of the 2nd comb box is the file name that I want to open when I hit the "Open" button. I have a known folder location.


    I have attached my code:

  • As long as the file extension (e.g., "pdf") is associated with a default application (e.g., Adobe Acrobat Reader), then you should be able to use something like this to open the file:

    Code
    1. Sub ShowFile(fName As String)
    2. Dim ShApp As Object, fso As Object
    3. Set ShApp = CreateObject("Shell.Application")
    4. Set fso = CreateObject("Scripting.FileSystemObject")
    5. If fso.FileExists(fName) Then
    6. CreateObject("Shell.Application").Open (fName)
    7. Else
    8. MsgBox "The file (" & fName & ")" & vbCrLf & "does not exist or you do not have permission to read it.", vbOKOnly, "File Not Found"
    9. End If
    10. End Sub
  • Hi,


    Change your Private Sub cmdOpen_Click() with this:


    Private Sub cmdOpen_Click()
    Dim sFilePath As String
    sFilePath = "C:\Users\jchan\Documents\My Documents\NHRA\Chassis Inspection Info\Chassis Specs\Chassis Specs" & cboChassisSpec.Text
    ActiveWorkbook.FollowHyperlink Address:=sFilePath


    End Sub