將一個工作簿拆分為多個工作表
1.打開要拆分的工作簿-【開發工具】-【宏】
2.輸入名稱,點擊創建。
3.輸入以下代碼。
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
4.返回到工作表中,點擊宏,選擇執行即可。