Add message box to confirm run macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Anyone...I would like to add a message box to my code that will prompt the
user with a "Yes" or "No" to confirm running a macro when the user clicks the
command button. If YES, then the macro resumes; however, if NO, then the
macros stops.

Thanks in advance...Andy
 
One way:

Dim nResult As Long
nResult = MsgBox( _
Prompt:="Really run this macro?", _
Buttons:=vbYesNo)
If nResult = vbYes Then
'Rest of macro macro
MsgBox "OK"
End If
 
I tried this and the macro still runs even when you select NO. can anyone
help. Thanks
 
Did you put the rest of your macro where I put

'Rest of macro

, i.e., within the If...End If structure?

Or are you saying that the Msgbox "OK" line was executed even if you
clicked NO??
 
I think J.E. hit the nail on the head. You didn't put your code in the correct
spot following his suggestion.

But maybe you could change the code just a bit:

Dim nResult As Long
nResult = MsgBox( _
Prompt:="Really run this macro?", _
Buttons:=vbYesNo)
If nResult = vbno Then
exit sub
End If

'rest of macro goes here now
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top