Sub 文件夹是否存在()
dim fso as object
Set fso = CreateObject("Scripting.FileSystemObject") '设fso为文件夹对象变量
If fso.FolderExists(ThisWorkbook.Path & "\Test") = True Then
MsgBox "Test文件夹存在"
Else
MsgBox "Test文件夹不存在"
MkDir ThisWorkbook.Path & "\Test"
End If
Set fso = Nothing
End Sub
注释 :
FileExists(路径+文件名): 检验文件是否存在,返回true,false
dim fso as object
Set fso = CreateObject("Scripting.FileSystemObject") '设fso为文件夹对象变量
If fso.FolderExists(ThisWorkbook.Path & "\Test") = True Then
MsgBox "Test文件夹存在"
Else
MsgBox "Test文件夹不存在"
MkDir ThisWorkbook.Path & "\Test"
End If
Set fso = Nothing
End Sub
注释 :
FileExists(路径+文件名): 检验文件是否存在,返回true,false