Sub 判断文件是否存在()
Dim myFileName As String
'指定带完整目录的文件夹名称
myFileName = "D:\Excel VBA其实很简单.xlsm"
If Len(Dir(myFileName, vbDirectory)) > 0 Then
MsgBox "该文件存在"
Else
MsgBox "该文件不存在"
End If
End Sub
Sub 判断文件是否存在()
Dim myFile As String
Dim fso As Scripting.FileSystemObject
myFile = "D:\Excel VBA其实很简单.xlsm" '指定带完整路径的文件名
Set fso = New Scripting.FileSystemObject
If fso.FileExists(myFile) = True Then
MsgBox "文件 " & myFile & " 存在"
Else
MsgBox "文件 " & myFile & " 不存在"
End If
Set fso = Nothing
End Sub