|
- Sub ykcbf() '//2024.8.22
-
- Application.ScreenUpdating = False
- With Application.FileDialog(msoFileDialogFolderPicker)
- .Title = "请选择文件夹"
- .InitialFileName = ThisWorkbook.Path & ""
- If .Show = -1 Then
- p = .SelectedItems(1) & ""
- End If
- End With
- getfds p
- End Sub
- Sub getfds(p)
- Set fso = CreateObject("Scripting.FileSystemObject")
- Dim fileName As String
- Dim icell As Integer
- Dim mywb As Workbook
-
- icell = 1
- 'Nowbookname = Mid(ThisWorkbook.FullName, InStrRev(ThisWorkbook.FullName, "") + 1)
- For Each fd In fso.GetFolder(p).SubFolders
- For Each f In fso.GetFolder(fd).Files
- fileName = Mid(f, InStrRev(f, "") + 1)
- 'fileName = Left(fileName, InStrRev(fileName, ".") - 1)
- If fileName = "1.xlsx" Then
- Set mywb = Workbooks.Open(f)
- 'Workbooks("1.xlsx").Worksheets("Sheet1").Range("2:2").CurrentRegion.Copy Workbooks("代码所在工作簿.xlsm").Worksheets("Sheet1").Range("icell:icell")
- '// mywb.Worksheets("Sheet1").Range("A1").CurrentRegion.Copy ThisWorkbook.Worksheets("Sheet1").Range("A" & icell)
- icell = ThisWorkbook.Worksheets("Sheet1").Range("A" & Rows.Count).End(3).Row + 1
- mywb.Worksheets("Sheet1").Range("A1").Range("A1:G2").Copy ThisWorkbook.Worksheets("Sheet1").Range("A" & icell)
- '// icell = icell + 2
- mywb.Close
- ' Workbooks("代码所在工作簿.xlsm").Worksheets("Sheet1").Range("A2").CurrentRegion.Copy Workbooks("代码所在工作簿.xlsm").Worksheets("Sheet2").Range("A2")
- 'Workbooks("代码所在工作簿.xlsm").Worksheets("Sheet1").Range("A1").CurrentRegion.Copy f.Worksheets("Sheet1").Range("D1")
- 'Workbooks.Close f
- End If
- Next
- getfds fd.Path
- Next fd
- Set fso = Nothing
- End Sub
复制代码
|
|