1Sub Sample()
23 Const folderPath = "C:\残業フォルダ\"
4 Const fileName = "残業_*.xlsx"
5 Const rngAddr = "D31:AM45"
67 Dim dic 'As Scripting.Dictionary
8 Dim fso 'As Scripting.FileSystemObject
910 Set dic = CreateObject("Scripting.Dictionary")
11 Set fso = CreateObject("Scripting.FileSystemObject")
1213 With fso
14 Application.ScreenUpdating = False
15 Dim f 'As File
16 For Each f In fso.GetFolder(folderPath).Files
17 If f.Name Like fileName Then
18 With Workbooks.Open(f.Path)
19 Dim ws As Worksheet
20 For Each ws In .Worksheets
21 dic.Add f.Path & vbTab & ws.Name, ws.Range(rngAddr).Value
22 Next
23 .Close False
24 End With
25 End If
26 Next
27 Application.ScreenUpdating = True
28 End With
2930 Set ws = Workbooks.Add.Worksheets(1)
31 Dim k, v, r, c, o
32 For Each k In dic
33 v = dic(k)
34 r = UBound(v, 1)
35 c = UBound(v, 2)
36 ws.Cells.Resize(r, c).Offset(o, 0).Value = v
37 ws.Cells.Resize(1, 2).Offset(o, c).Value = Split(k, vbTab)
38 o = o + r
39 Next
40 ws.UsedRange.EntireColumn.AutoFit
41End Sub
42