我正在使用此代码将所有数据从已关闭工作簿中的工作表复制到目标工作簿。但是,此代码循环遍历每个单元格,并且由于源工作簿包含 40,000 行,因此花费的时间太长。可以对此代码进行哪些更改以将所有数据从源工作表复制到目标工作簿中的特定工作表,而无需遍历单元格,或者如果您可以提供替代解决方案。感谢您的帮助
Sub GetDataDemo()
Dim FilePath$, Row&, Column&, Address$
Const FileName$ = "Book1.xls"
Const SheetName$ = "Sheet1"
Const NumRows& = 40000
Const NumColumns& = 10
FilePath = ActiveWorkbook.Path & "\"
'***************************************
DoEvents
Application.ScreenUpdating = False
If Dir(FilePath & FileName) = Empty Then
MsgBox "The file " & FileName & " was not found", , "File Doesn't Exist"
Exit Sub
End If
For Row = 1 To NumRows
For Column = 1 To NumColumns
Address = Cells(Row, Column).Address
dest. Cells(Row, Column) = GetData(FilePath, FileName, SheetName, Address)
Columns.AutoFit
Next Column
Next Row
ActiveWindow.DisplayZeros = False
End Sub
Private Function GetData(Path, File, Sheet, Address)
Dim Data$
Data = "'" & Path & "[" & File & "]" & Sheet & "'!" & _
Range(Address).Range("A1").Address(, , xlR1C1)
GetData = ExecuteExcel4Macro(Data)
End Function