这个问题在这里已有答案:
我试图运行一个宏来检查文件是否存在。我得到编译Sub or function not defined
的错误。请有人帮忙吗
If FileExists(filepath) Then
Else
Call Master
Call PrinttoPDF
End If
尝试以下子。
Sub CheckFilePath()
If Dir(FilePath, vbNormal) <> "" Then
Call Master
Call PrinttoPDF
Else
MsgBox "File does not exists."
End If
End Sub
我不是VBA大师,但它看起来像FileExists
,Master
或PrinttoPDF
不存在作为Sub或Function。也许改变案例,最后一个应该是PrintToPdf
。
我希望错误告诉你错误发生在哪一行。
我在this page上找到了一个可以解决的工作示例:
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