I have a button that triggers a chain of events. One of these events is to delete a sheet. Before the user deletes anything, I pop up my custom YES/NO message asking them to confirm the whole process.
Then comes the sub event of deleting the sheet, and Excel pops up its own window for confirming the removal of the sheet. Problem is that if the user says "no" at that point, that sets my application in an inconsistent state.
How can I bypass Excel asking to confirm the deletion of a sheet ?
You can also press ALT + F8 to open the Macro dialog box. ❼ From the Macro dialog box, select the function name of the VBA code and hit Run. This will instantly delete the sheet that you have inserted in the VBA code without showing any prompt warning message.
That is, oldvalue = Application. DisplayAlerts , Application. DisplayAlerts = False , sheet. Delete , Application.
To delete a sheet using VBA, you need to use the VBA Delete method. You need to specify the sheet that you want to delete and then use this method. Let's say if you want to delete the “Sheet1”, then you need to mention sheet1 and then type a dot (.) and in the end, type “Delete”.
You can delete any sheet using VBA. Just write Sheets("Sheetname"). delete.
You can change the default display alert parameter of Excel using:
Application.DisplayAlerts = False
don't forget to restore the standard behavior at the end of your process:
Application.DisplayAlerts = True
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With