您好,欢迎来到九壹网。
搜索
您的当前位置:首页合并工作表

合并工作表

来源:九壹网
Sub aaa()

Dim d As Object, wb As Workbook, sht As Worksheet

Dim i As Integer, k, myPath As String, myFileName As String, temp As String

Application.ScreenUpdating = False

Application.DisplayAlerts = False

Set d = CreateObject(\"Scripting.Dictionary\")

myPath = ThisWorkbook.Path & \"\\元数据\\\"

myFileName = Dir(myPath & \"*.xlsx\")

Do While myFileName <> \"\"

Set wb = GetObject(myPath & myFileName)

For Each sht In wb.Sheets

If Not d.exists(sht.Name) Then

d(sht.Name) = \"\"

Workbooks.Add (xlWBATWorksheet)

Sheets(1).Name = \"临时\"

ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & \"\\\" & sht.Name & \".xlsx\"

With ActiveWorkbook

temp = Left(wb.Name, Len(wb.Name) - 4)

.Sheets.Add(After:=.Sheets(.Sheets.Count)).Name = temp

sht.Cells.Copy .Sheets(temp).Range(\"A1\")

.Sheets(\"临时\").Delete

End With

Else

With Workbooks(sht.Name & \".xlsx\")

temp = Left(wb.Name, Len(wb.Name) - 4)

.Sheets.Add(After:=.Sheets(.Sheets.Count)).Name = temp

sht.Cells.Copy .Sheets(temp).Range(\"A1\")

End With

End If

Next

wb.Close False

myFileName = Dir()

Loop

k = d.keys

For i = 0 To d.Count - 1

Workbooks(k(i) & \".xlsx\").Close True

Next

Application.DisplayAlerts = True

Application.ScreenUpdating = True

MsgBox \"处理完毕\"

End Sub

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 91gzw.com 版权所有 湘ICP备2023023988号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务