VBA 创建文件夹和判断文件夹是否存在!
Public Function 创建文件夹(ByVal 路径 As String, ByVal 文件夹名称 As String)
Dim folder As Object
'设置FSO对象
Set fso = CreateObject("Scripting.FileSystemObject")
'如果文件夹不存在就创建
On Error Resume Next
If Not (fso.Folderexists(路径 & 文件夹名称)) Then
Set folder = fso.Createfolder(路径 & 文件夹名称)
MsgBox "< " & 文件夹名称 & " >文件夹创建成功!", vbInformation, "VB小源码提醒您!"
Else
MsgBox "< " & 文件夹名称 & " >文件夹已经存在!", vbInformation, "VB小源码提醒您!"
End If
End Function
使用方法:
Sub a()
Call 创建文件夹("C:\Users\", "文件名称")
End Sub