VBA获取多个文件夹获取他的路径
时间: 2023-05-13 09:07:36 浏览: 96
你可以使用 VBA 中的 FileSystemObject 对象来获取多个文件夹的路径。以下是一个示例代码:
Sub GetFolderPaths()
Dim fso As Object
Dim folderPath As String
Dim folderPaths() As String
Dim i As Integer
Set fso = CreateObject("Scripting.FileSystemObject")
'设置要获取路径的文件夹
folderPaths = Array("C:\Folder1", "C:\Folder2", "C:\Folder3")
'循环获取每个文件夹的路径
For i = LBound(folderPaths) To UBound(folderPaths)
folderPath = folderPaths(i)
Debug.Print folderPath
Next i
Set fso = Nothing
End Sub
这段代码会输出每个文件夹的路径,你可以根据需要进行修改。
相关问题
VBA获取多个文件夹路径
您好,以下是获取多个文件夹路径的 VBA 代码示例:
Sub GetFolderPath()
Dim FolderPath As String
Dim SelectedFolders As Variant
'弹出选择文件夹对话框
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "请选择文件夹"
.AllowMultiSelect = True
If .Show <> -1 Then Exit Sub
'获取选择的文件夹路径
For Each SelectedFolders In .SelectedItems
FolderPath = SelectedFolders
Debug.Print FolderPath
Next
End With
End Sub
希望能对您有所帮助!
VBA选择多个文件夹路径
可以使用 FileDialog 对象来实现选择多个文件夹路径的功能,具体代码如下:
Sub SelectFolders()
Dim fd As FileDialog
Dim folderPath As Variant
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
fd.AllowMultiSelect = True
fd.Title = "请选择文件夹"
If fd.Show = -1 Then
For Each folderPath In fd.SelectedItems
Debug.Print folderPath
Next folderPath
End If
End Sub
这段 VBA 代码会弹出一个文件夹选择对话框,允许用户选择多个文件夹路径,并将选择的文件夹路径打印到调试窗口中。
阅读全文