I am trying to run a macro to check if a file exists. I get compiling error that Sub or function not defined
. Can someone help please
If FileExists(filepath) Then
Else
Call Master
Call PrinttoPDF
End If
I am trying to run a macro to check if a file exists. I get compiling error that Sub or function not defined
. Can someone help please
If FileExists(filepath) Then
Else
Call Master
Call PrinttoPDF
End If
Try following sub.
Sub CheckFilePath()
If Dir(FilePath, vbNormal) <> "" Then
Call Master
Call PrinttoPDF
Else
MsgBox "File does not exists."
End If
End Sub
I'm no VBA guru, but it looks like either FileExists
, Master
, or PrinttoPDF
doesn't exist as a Sub or Function. Maybe change the Case, the last one should probably be PrintToPdf
.
I would expect the error to tell you which line the error occurred on.
There is a working example I found on this page that you could work through:
Sub Test_File_Exist_With_Dir()
Application.ScreenUpdating = False
Dim FilePath As String
FilePath = ""
On Error Resume Next
FilePath = Dir("C:\Users\DT168\Desktop\Test folder\Book2.xlsx")
On Error GoTo 0
If FilePath = "" Then
MsgBox "File doesn't exist", vbInformation, "Kutools for Excel"
Else
MsgBox "File exist", vbInformation, "Kutools for Excel"
End If
Application.ScreenUpdating = False
End Sub