【发布时间】:2019-08-05 01:48:23
【问题描述】:
我正在尝试运行宏来检查文件是否存在。我收到Sub or function not defined 的编译错误。有人可以帮忙吗
If FileExists(filepath) Then
Else
Call Master
Call PrinttoPDF
End If
【问题讨论】:
我正在尝试运行宏来检查文件是否存在。我收到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 存在。也许换个Case,最后一个应该是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
【讨论】: