I'm trying to clear the worksheet and delete any added worksheets when the workbook is closed. this is the code I put in ThisWorkbook, but it doesn't work.
Code:
Private Sub Workbook_Deactivate()
Set ws9 = Sheet9
ws9.Cells.Delete
Dim ws As Worksheet
Application.DisplayAlerts = False
For Each ws In Worksheets
If ws.Name <> "Main Sheet" Then ws.Delete
Next
End Sub