我正在尝试从VBA复制工作表。这是我的代码:
'Create a new excel workbook and copy two result sheets.
Public Function copyAsSaveResultSheets(filePath As String)
'Remove alert for confirmations
Application.DisplayAlerts = False
'Get new work book
Dim newWorkBook As Workbook
Set newWorkBook = Workbooks.Add
'Copy result sheet
'When click "Debug" cursor is here.
ThisWorkbook.Sheets("ResultProcess").Copy Before:=newWorkBook.Sheets(1)
ThisWorkbook.Sheets("ResultCode").Copy Before:=newWorkBook.Sheets(1)
'Delete default sheet
For Each sheet In Worksheets
Select Case sheet.Name
Case "Sheet1", "Sheet2", "Sheet3"
sheet.Delete
End Select
Next
'Save work book
newWorkBook.SaveAs filePath
'Close new work book
ActiveWorkbook.Close
'Available showing alert from application
Application.DisplayAlerts = True
End Function
运行此代码时,出现此错误:
我的代码中没有发现任何错误。 “ResultProcess”表和“ResultCode”表根据要求受到保护。这有关系吗?