Zi 字媒體
2017-07-25T20:27:27+00:00
今天我來結合一個實際案例,介紹將總表按工作表拆分為多個工作簿的方法。比如:在下圖所示數據總表中包含多個工作表,需要將每個工作表拆分為多個單獨的文件。第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 = TrueEnd Sub如果你覺得有用,就分享給朋友們看看吧~End.本文為統計網原創文章,需要轉載請聯繫統計網(),轉載時請註明作者及出處,並保留本文鏈接。
寫了
5860316篇文章,獲得
23313次喜歡