Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete Sheets and avoid Excel asking the user to confirm, using custom messages instead

Tags:

excel

vba

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 ?

like image 350
BuZz Avatar asked Jan 19 '12 09:01

BuZz


People also ask

How do I delete a sheet in Excel VBA without confirmation?

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.

What VBA statement would you use to prevent Excel from requiring users to confirm actions?

That is, oldvalue = Application. DisplayAlerts , Application. DisplayAlerts = False , sheet. Delete , Application.

How do I delete a worksheet in VBA?

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”.

How do you force delete a sheet in Excel?

You can delete any sheet using VBA. Just write Sheets("Sheetname"). delete.


1 Answers

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 
like image 192
JMax Avatar answered Oct 15 '22 04:10

JMax