帮我写一段Excel的VBA代码,将一个工作簿的所有工作簿分离成独立的工作簿
时间: 2024-06-07 21:05:13 浏览: 147
VBA拆分工作簿.xls
5星 · 资源好评率100%
好的,以下是可以帮助您分离工作簿的VBA代码:
Sub 分离工作簿()
Dim wb As Workbook
Dim newWb As Workbook
Dim ws As Worksheet
Dim savePath As String
For Each wb In Workbooks
For Each ws In wb.Worksheets
Set newWb = Workbooks.Add
ws.Copy Before:=newWb.Sheets(1)
newWb.Sheets(2).Delete
savePath = ThisWorkbook.Path & "\" & wb.Name & "_" & ws.Name & ".xlsx"
newWb.SaveAs savePath
newWb.Close
Next ws
Next wb
End Sub
请将代码复制粘贴到Excel的VBA编辑器中,并在需要分离工作簿的时候运行该代码即可。
阅读全文