Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add "Are you sure?" to my excel button, how can I?

Tags:

I have a button on my form that clears the entire 8 sheet workbook. I do want to clear it occasionally, but I would hate to do it by accident. I've tried googling it, but every result I've found assumes I have a much firmer grasp of VBA than I do. How can I make it so when the button is clicked a Dialog box pops up saying "This will erase everything! Are you sure? [Continue] [Cancel]"? Thanks.

like image 937
aslum Avatar asked Dec 20 '11 00:12

aslum


2 Answers

On your existing button code, simply insert this line before the procedure:

If MsgBox("This will erase everything! Are you sure?", vbYesNo) = vbNo Then Exit Sub 

This will force it to quit if the user presses no.

like image 65
Matt Donnan Avatar answered Sep 22 '22 12:09

Matt Donnan


Create a new sub with the following code and assign it to your button. Change the "DeleteProcess" to the name of your code to do the deletion. This will pop up a box with OK or Cancel and will call your delete sub if you hit ok and not if you hit cancel.

Sub AreYouSure()  Dim Sure As Integer  Sure = MsgBox("Are you sure?", vbOKCancel) If Sure = 1 Then Call DeleteProcess  End Sub 

Jesse

like image 23
Jesse Avatar answered Sep 19 '22 12:09

Jesse