I'm trying to test if a file exists with VBA on Mac Office 2011.
My macro is working with Office 2004 but doesn't work with 2011.
I'm using the Dir function. If the function returns nothing, this means the file doesn't exist. But with Office 2011, the function returns an error code 76 when the file doesn't exist.
You can just create your own function that handles the error. For instance, something like this:
Function FileExists(ByVal AFileName As String) As Boolean
On Error GoTo Catch
FileSystem.FileLen AFileName
FileExists = True
GoTo Finally
Catch:
FileExists = False
Finally:
End Function
Sub Test()
If FileExists("Macintosh HD:Library:User Pictures:Flowers:Flower.tif") Then
MsgBox "File exists"
Else
MsgBox "File doesn't exists"
End If
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With