Vba Active Worksheet Delete. In the above example we have deleted active sheet from a workbook using Delete method of worksheet object. It is like when you would say : delete this sheets, and if it fails I.
Adds new sheet before active sheet Set sht = ThisWorkbook. Add ' Set the name of sheet sht. The macro first declares an object called ws.
To delete the active sheet, you can use the "ActiveSheet" object instead of using the sheet name to specify the sheet.
Excel VBA Worksheets VBA Activesheet vs Worksheets, Select, Activate etc.
If there was a Before Delete Worksheet event, I could check the name of the worksheet, and if required, cancel the event. Difference between Worksheets and Sheets in VBA. When you execute this code, Sheets.