Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"
like image 808
Adrian Gornall Avatar asked Oct 22 '25 20:10

Adrian Gornall


1 Answers

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" 
like image 120
AER Avatar answered Oct 25 '25 00:10

AER



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!