各位神手午安,最近在写将活页簿内不同工作表另存成不同档案的小程式。
但三不五时会跑出 Class Worksheet的Copy方法失败的error '1004'。
奇怪的是偶尔会偶尔不会,或是跑几个循环后就error,请问各位可以修改的方向或范例,
感激不尽,版本是Office 2010,程式如下:
Sub splitbook()
Dim xPath as string
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlarts = False
For Each xWs in ActiveWorkbook.Sheets
xWs.Copy
Application.ActiveWorkbook.SaveAs Filename:=xPath & "\" & xWs.Name, _
FileFormat:=xlOpenXMLWorkbook
Application.ActiveWorkbook.Close False
Next
Application.DisplayAlarts = True
Application.ScreenUpdating = True
End Sub