Sub 按钮1_Click()
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then mypath = .SelectedItems(1) Else Exit Sub
End With
If Right(mypath, 1) <> "\" Then mypath = mypath & "\"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set sh = ThisWorkbook.Sheets(1)
sh.UsedRange.Offset(1).ClearContents
r = 2
For Each f In sh.subfolders("scripting.filesystemobject").getfolder(mypath).Files
With Workbooks.Open(f)
.Sheets(1).UsedRange.Offset(2).Copy sh.Cells(r, 1)
r = sh.Cells(Rows.Count, 1).End(3).Row + 1
.Close False
End With
Next f
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
目前这个代码只能支持当前文件夹的汇总,可以修改成支持子文件夹吗
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show Then mypath = .SelectedItems(1) Else Exit Sub
End With
If Right(mypath, 1) <> "\" Then mypath = mypath & "\"
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set sh = ThisWorkbook.Sheets(1)
sh.UsedRange.Offset(1).ClearContents
r = 2
For Each f In sh.subfolders("scripting.filesystemobject").getfolder(mypath).Files
With Workbooks.Open(f)
.Sheets(1).UsedRange.Offset(2).Copy sh.Cells(r, 1)
r = sh.Cells(Rows.Count, 1).End(3).Row + 1
.Close False
End With
Next f
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
目前这个代码只能支持当前文件夹的汇总,可以修改成支持子文件夹吗