将多个相同工作簿内容复制汇总到一个工作簿VBA代码
作者:互联网
Sub Excel文件打开对话框()
''''复制子表中的所有内容粘贴到母表
Dim filename As Variant, i As Byte
Dim wb As Workbook
Dim sht_zhis As Worksheet
Dim sht As Worksheet
Dim l_begin As Integer
Dim l_begin_moth As Integer '
Set sht_zhis = ThisWorkbook.Sheets(1) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
l_begin = 4 '子表表头行(可修改)
filename = Application.GetOpenFilename("2003格式 (*.xls;*.xla), *.xls;xla ,2007格式 (*.xl??), *.xl??", 2, "打开Excel文件", MultiSelect:=True)
If VBA.IsArray(filename) Then
For i = LBound(filename) To UBound(filename)
Set wb = GetObject(filename(i))
Set sht = wb.Sheets(1) '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
ThisWorkbook.Activate
n_z = sht.Range("A10000").End(xlUp).Row '子表中总行数
sht_zhis.Range(Cells(sht_zhis.Range("a60000").End(xlUp).Row + 1, 1), Cells(sht_zhis.Range("a60000").End(xlUp).Row + n_z - l_begin, 100)) = sht.Range("A" & l_begin + 1).Resize(n_z - l_begin, 100).Value
' arr = sht.Range("A" & l_begin + 1).Resize(n_z - l_begin, 100)
wb.Close
Next i
End If
End Sub
标签:Dim,begin,sht,zhis,汇总,VBA,filename,工作,Range 来源: https://www.cnblogs.com/codinglifemrgao/p/14411382.html