今天我来结合一个实际案例,介绍将总表按工作表拆分为多个工作簿的方法。
比如:在下图所示数据总表中包含多个工作表,需要将每个工作表拆分为多个单独的文件。
第4步中的vba代码如下。
Sub 工作表为拆分工作簿()
On Error Resume Next
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim Sht As Worksheet, Nwb As Workbook, Owb As Workbook
Dim OPath As String, NPath As String
Set Owb = ActiveWorkbook
OPath = Owb.Path
If Len(OPath) 0 Then
NPath = OPath & "" & "\" & Split(Owb.Name, ".x")(0) & "-拆分"
MkDir NPath
For Each Sht In Owb.Worksheets
Sht.Copy
Set Nwb = ActiveWorkbook
Nwb.SaveAs NPath & "" & "\" & Split(Owb.Name, ".x")(0) & "-" & Sht.Name & ".xlsx"
Nwb.Close
Next
MsgBox "拆分后的文件已保存至:" & NPath
End If
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
如果你觉得有用,就分享给朋友们看看吧~
End.
作者:李锐(中国统计网特邀认证作者)
本文为中国统计网原创文章,需要转载请联系中国统计网(小编微信:itongjilove),转载时请注明作者及出处,并保留本文链接。