'path:1、D:\vba 2、D:\vba\ 兩種格式都可以
'如果路徑存在,外層if結束
'如果路徑path是D:\vba\1.txt,程序會認爲路徑下不存在該文件夾,則創建新的文件夾,
'而如果1.txt這個文本文件在該目錄下存在,報錯,errorNumber>0,程序結束。
If Not CreateObject("Scripting.FileSystemObject").FolderExists(path) Then
On Error Resume Next '捕捉錯誤的內容並繼續運行
CreateObject("Scripting.FileSystemObject").CreateFolder (path)
If Err.Number > 0 Then
MsgBox "errorMsg:" & Err.Description ' 彈框顯示錯誤信息
Err.Clear
'處理強制結束
End
End If
End If