Word/VBA - How to check if a file or directory exists

Posted in: VB6 / VBA
By dePoPo
Jul 15, 2009 - 5:02:13 PM

This function can be used in a word macro to check if a certain file or directory is present on the file system.

' --- Check if a file or directory is present, and return TRUE or
'     FALSE to indicate the state.

Function FileDirExists(s_pathhandle As String) As Boolean
 
    Dim dummy As Integer
    On Error Resume Next
    dummy = GetAttr(s_pathhandle)
    Select Case Err.Number
    Case Is = 0
        FileDirExists = True
    Case Else
        FileDirExists = False
    End Select
    
    On Error GoTo 0
End Function


Visitor Comments