When I run the macro in excel, there is a message box come out.
There is two options "Delete" and "Cancel". I always need to press the "Delete" button. What is the vba code for pressing the "Delete" button?
When I run the macro in excel, there is a message box come out.
There is two options "Delete" and "Cancel". I always need to press the "Delete" button. What is the vba code for pressing the "Delete" button?
If you designed userform for confirm delete, you need to set property for command Delete (Default=true)Originally Posted by clif
If use Msgbox, try this code:
Sub AskAndDo() If MsgBox("Are you sure ?", vbYesNo + vbQuestion) = vbNo Then Exit Sub Else 'Code goes here End If End Sub
Might try this:
[vba]Application.OnKey "{DELETE}"[/vba]
or
[vba]Application.OnKey "{DEL}"[/vba]
Ron
Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes.
Well, if it's your macro and you always press the delete button, program it to to not have the Delete/Cancel dialog box at all.Originally Posted by clif
Now ,,, guessing here ... if it's an Excel box, like when your macro deletes a worksheet and Excel asks "Are You Sure?", then you can control that by .DisplayAlerts as below
[VBA]
Application.DisplayAlerts = False
On Error Resume Next
Worksheets(ws).Delete
On Error GoTo 0
Application.DisplayAlerts = True
[/VBA]
Paul
clif, Paul is guessing because you didn't provide the information necessary to answer your question.
How about posting the code in question? That would help us in our efforts to help you and it would probably not have taken as many posts as it did so far because no one knows what you are looking at.
Steve
"Nearly all men can stand adversity, but if you want to test a man's character, give him power."
-Abraham Lincoln
Thanks all
clif, did Paul's answer solve your problem? If so, could you please mark your thread solved using the thread tools at the top of the page?
Steve
"Nearly all men can stand adversity, but if you want to test a man's character, give him power."
-Abraham Lincoln