如何透過vba產生資料夾??
Scripting.FileSystemObject作法:
Sub TEST1()
Dim fs As Object
Dim newFolder As Object
Dim folderPath As String
' 建立 FileSystemObject
Set fs = CreateObject("Scripting.FileSystemObject")
' 設定新資料夾的路徑
folderPath = "C:\MyNewFolder"
' 建立新資料夾
Set newFolder = fs.CreateFolder(folderPath)
' 顯示訊息
MsgBox "已成功建立資料夾:" & folderPath
End Sub
更簡單的方式,使用MkDir:
Sub TEST12()
Dim folderPath As String
Dim newFolder As String
Dim i As Integer
Dim NumFolders_I As Integer
' 設定父資料夾路徑
folderPath = "C:\Users\YourUsername\Documents\Projects\"
' 設定要建立的資料夾數量
NumFolders_I = 10
' 建立資料夾
For i = 1 To NumFolders
FolderName = "Project_" & i
MkDir folderPath & FolderName
Next i
End Sub
沒有留言:
張貼留言