使用VBA 1分钟合并多个有相同结构的工作簿文件到一个工作表中

  • A+
所属分类:VBA编程

合并多个有相同结构的工作簿文件 到一个工作表中,使用VBA,1分钟搞定;不行试试看,代码先下面,复制即可;

后面写个稍微详细点的例子;

直接复制下面的的代码,就可以了

Sub 合并多个工作簿()
Dim MyPath$, MyName$, sh As Worksheet, sht As Worksheet, m&
Set sh = ActiveSheet
MyPath = ThisWorkbook.Path & "\"
MyName = Dir(MyPath & "*.*")
Application.ScreenUpdating = False
Cells.ClearContents
Do While MyName <> ""
If MyName <> ThisWorkbook.Name Then
With GetObject(MyPath & MyName)
For Each sht In .Sheets
If IsSheetEmpty = IsEmpty(sht.UsedRange) Then
m = m + 1
If m = 1 Then
sht.[a1].CurrentRegion.Copy sh.[a1]
Else
sht.[a1].CurrentRegion.Copy sh.[a65536].End(xlUp).Offset(1)
End If
End If
Next
.Close False
End With
End If
MyName = Dir
Loop
Application.ScreenUpdating = True
End Sub

 

  • 公众号:i95556
  • 计算机二级考生请关注
  • weinxin
  • 公众号:word_excel_ppt
  • 学习OFFICE请关注
  • weinxin
iexcel

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: