您可以使用类似这样的方法来循环浏览所选文件夹中的文件夹:
Dim sPath As String
Dim sFil As String
Dim FolderPath As String
Dim diaFolder As FileDialog
' Open the file dialog
Set diaFolder = Application.FileDialog(msoFileDialogFolderPicker)
diaFolder.AllowMultiSelect = False
diaFolder.Show
FolderPath = diaFolder.SelectedItems(1)
' Cycle through spreadsheets in selected folder
sPath = FolderPath & "\" 'location of files
sFil = Dir(sPath & "*.csv") 'change or add formats
Do While sFil <> "" 'will start LOOP until all files in folder sPath have been looped through
Set oWbk = Workbooks.Open(sPath & "\" & sFil) 'opens the file
' do something
oWbk.Close True
sFil = Dir
Loop
然后你可以把你的代码复制到它说的地方'do something