Monday, October 14, 2013

Is it there? Files and Folders

Which "it"?  The file or folder, referenced in code.  

Here are a couple of handy, no UI to fix errors so they run more quickly, utilities to make certain that character string points to a file or folder.  The differentiating line is highlighted

Function IsAvailableFolder(Optional FolderWithPath) As Boolean
    On Error GoTo IsAvailableFolder_Error
    IsAvailableFolder = (GetAttr(FolderWithPath) And vbDirectory) = vbDirectory
    GoTo IsAvailableFolder_Exit
IsAvailableFolder_Error:
    IsAvailableFolder = False
IsAvailableFolder_Exit:
    On Error GoTo 0
End Function

Function IsAvailableFile(Optional FileWithPath) As Boolean
    On Error GoTo IsAvailableFile_Error
    IsAvailableFile = Not (GetAttr(FileWithPath) And vbDirectory) = vbDirectory
    GoTo IsAvailableFile_Exit
IsAvailableFile_Error:
    IsAvailableFile = False
IsAvailableFile_Exit:
    On Error GoTo 0
End Function