Предполагая, что ячейка A1 заполнена на листе Report
, вы можете использовать SQL для подключения к рабочим книгам .xlsm и затем извлечь нужные ячейки.Нечто подобное должно работать для вас, и, надеюсь, будет быстрее:
Sub tgr()
'Requires Tools -> References "Microsoft AvctiveX Data Objects 2.1" (or higher; I used 6.1)
Dim sqlConn As ADODB.Connection
Dim sqlRS As ADODB.Recordset
Dim rDest As Range
Dim aResults() As Variant
Dim sFolder As String
Dim sFile As String
Dim ixResult As Long
Dim ixSQL As Long
'Change to the correct workbook, sheet, and cell that results should start on
Set rDest = ActiveWorkbook.Worksheets("Sheet1").Range("A11")
sFolder = "C:\Users\maxd\OneDrive - Nortek, Inc\Coil Test Data\coils_35_and_36\36\WET\Testing\" 'REMEMBER END BACKSLASH
sFile = Dir(sFolder & "*.xlsm")
'Assumes a maximum of 65000 results
'14 columns to populate A:N
ReDim aResults(1 To 65000, 1 To 14)
'These are the column numbers (1 = A, 2 = B, etc). Change as needed if column order ever needs to be adjusted
Const YearCol As Long = 1
Const CFMCol As Long = 2
'No result for column 3 (C) ?
Const FaceVelCol As Long = 4
Const AVGCapCol As Long = 5
Const APDCol As Long = 6
Const WPDCol As Long = 7
Const InletDBCol As Long = 8
Const InletWBCol As Long = 9
'No result for column 10 (J) ?
Const InletWTCol As Long = 11
Const OutletWTCol As Long = 12
Const HeatBalCol As Long = 13
Const FileNameCol As Long = 14
Do While Len(sFile) > 0
Set sqlConn = New ADODB.Connection
Set sqlRS = New ADODB.Recordset
sqlConn.provider = "Microsoft.ACE.OLEDB.12.0"
sqlConn.ConnectionString = "Data Source='" & sFolder & sFile & "';Extended Properties=""Excel 12.0 Xml;HDR=YES"";"
sqlConn.Open
On Error Resume Next
sqlRS.Open "SELECT * FROM [Report$]", sqlConn, adOpenKeyset
On Error GoTo 0
If sqlRS.State <> 0 Then
ixSQL = 0
ixResult = ixResult + 1
If Not sqlRS.BOF Then sqlRS.MoveFirst
Do Until sqlRS.EOF = True
ixSQL = ixSQL + 1
Select Case ixSQL
Case 8: aResults(ixResult, YearCol) = sqlRS(4).Value
Case 15: aResults(ixResult, InletWTCol) = sqlRS(11).Value
Case 16: aResults(ixResult, OutletWTCol) = sqlRS(11).Value
Case 21: aResults(ixResult, InletDBCol) = sqlRS(3).Value
aResults(ixResult, HeatBalCol) = sqlRS(11).Value
Case 22: aResults(ixResult, InletWBCol) = sqlRS(3).Value
Case 28: aResults(ixResult, APDCol) = sqlRS(3).Value
Case 29: aResults(ixResult, CFMCol) = sqlRS(3).Value
Case 33: aResults(ixResult, WPDCol) = sqlRS(3).Value
Case 35: aResults(ixResult, AVGCapCol) = sqlRS(3).Value
End Select
aResults(ixResult, FaceVelCol) = aResults(ixResult, CFMCol) / 6.25 '(30 * 30 / 144) = 6.25
aResults(ixResult, FileNameCol) = sFile
sqlRS.MoveNext
Loop
sqlRS.Close
End If
sqlConn.Close
Set sqlRS = Nothing
Set sqlConn = Nothing
sFile = Dir
Loop
If ixResult > 0 Then rDest.Resize(ixResult, UBound(aResults, 2)).Value = aResults
End Sub