Open a PDF

ddrew

seasoned user
Local time
Today, 19:03
Joined
Jan 26, 2003
Messages
911
I need to open a PDF file from a button, now I know th easy way to do this is via the hyperlink in proporties. The problem is the file may or may not be present. It will always be named exactly the same.

I'm assuming that I need to do this in VBA. I have done the code to check if the folder is present (and make the folder if needs be) and I think I can check to see if the file exists, what I dont know is how to actually open the file.

Code:
    Dim strhelp As String    'The help folder
    Dim strHelpDoc As String
    
    strhelp = "c:\GPandDetectionDogTrainingLog\Help"
    strHelpDoc = "c:\GPandDetectionDogTrainingLog\Help\Help.pdf"
    
    If Len(Dir(strhelp, vbDirectory)) = 0 Then
        MkDir strhelp
    End If
 
Look at FollowHyperlink in VBA help.
 
Thanks for yoru help, well Im nearly there. I just need to check that the file exists. I searched and foun this code but its not working, it always says the the file dosent exist even when I know it does

Code:
    Dim strhelp As String    'The help folder
    Dim strHelpDoc As String        'The help file

    strhelp = "c:\GPandDetectionDogTrainingLog\Help"
    strHelpDoc = "c:\GPandDetectionDogTrainingLog\Help\Help.pdf"

    'If the Dir dosen't exist then create it
    If Len(Dir(strhelp, vbDirectory)) = 0 Then
        MkDir strhelp
    End If

    'If the file dosent exist
    If Dir("strHelpDoc") <> "" Then
        Application.FollowHyperlink strHelpDoc, , True
    Else
        MsgBox "File dosen't exist"
    End If

I also tried this, with the same result:

Code:
    Dim strhelp As String    'The help folder
    Dim strHelpDoc As String    'The help file

    strhelp = "c:\GPandDetectionDogTrainingLog\Help"
    strHelpDoc = "c:\GPandDetectionDogTrainingLog\Help\Help.pdf"
   
    'If the Dir dosen't exist then create it
    If Len(Dir(strhelp, vbDirectory)) = 0 Then
        MkDir strhelp
    End If

    'If the file dosent exist
    If Len(Dir("strHelpDoc")) = 0 Then
        MsgBox "File dosen't exist"
    Else
        Application.FollowHyperlink strHelpDoc, , True
    End If
 
Last edited:
you have unnecessary double quotes try

Code:
If Len(Dir(strHelpDoc)) = 0 Then
 

Users who are viewing this thread

Back
Top Bottom