Adrian Gornall
Adrian Gornall

Reputation: 327

Delete a worksheet and recreate with the same sheet name

I'm currently trying to delete a worksheet and auto create a new worksheet with the same name.

I'm using the below code. However, when i run the code the windows pop up appears asking me to confirm deletion, i want to prevent this and just delete and replace with a new sheet. I want to avoid Send-keys for this.

ThisWorkbook.Sheets("Process Map").delete
ThisWorkbook.Sheets.Add.Name = "Process Map"

Upvotes: 4

Views: 13242

Answers (1)

AER
AER

Reputation: 1531

Try setting the DisplayAlerts to False (then back to true if that is what you want as the default setting.

Application.DisplayAlerts = False
On Error Resume Next 
ThisWorkBook.Sheets("Process Map").Delete 
On Error Goto 0 
Application.DisplayAlerts = True
ThisWorkbook.Sheets.Add.Name = "Process Map" 

Or without error handling:

Application.DisplayAlerts = False
ThisWorkBook.Sheets("Process Map").Delete 
Application.DisplayAlerts = True
ThisWorkbook.Sheets.Add.Name = "Process Map" 

Upvotes: 7

Related Questions