I am trying to write a macro that specifically deletes a sheet named "T.O.C." . I select the sheet by its name and then used edit.Delete, but it gives me the error "None of the selected entities could be deleted". I tried looking this up on the web before coming here, and the responses to this same question don't help. The macro recorder is no help either. Can someone please point me in the right direction?
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDrawing As SldWorks.DrawingDoc
Dim boolStatus As Boolean
Sub DeleteTOCSheet()
' Initialize SolidWorks application
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
' Ensure the document is a drawing
If swModel Is Nothing Or swModel.GetType() <> swDocDRAWING Then
MsgBox "This macro must be run in a drawing document.", vbExclamation
Exit Sub
End If
' Get the drawing document
Set swDrawing = swModel
' Try to select the sheet named "T.O.C."
boolStatus = swDrawing.Extension.SelectByID2("T.O.C.", "SHEET", 0, 0, 0, False, 0, Nothing, 0)
' Check if selection was successful
If boolStatus Then
swModel.EditDelete ' Deletes the selected sheet
Else
MsgBox "Sheet 'T.O.C.' not found.", vbExclamation
End If
End Sub