Macro - msgbox

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

Guest

I have a rather large macro, and I want to give the user a chance to exit the
macro before it runs. I need a msgbox (or a dialogue?) with a warning, and
the user will select either OK (to run the defined macro) or cancel (to exit
and not run the macro).

Can anyone help me?

Thanks:)
 
traima, here is an example of one with an option if yes no and cancel

Sub Message_box_test()

Dim Msg, Title, Response As String

Msg = "Put message here"

Title = "Put title here"

Response = MsgBox(Msg, vbYesNoCancel + vbQuestion, Title)



If Response = vbNo Then

'your code if no is clicked here

MsgBox "you clicked no"

Exit Sub ' Quit the macro

End If



If Response = vbCancel Then

'your code if Cancel is clicked here

MsgBox "You clicked cancelled"

Exit Sub ' Quit the macro

End If



'your code if Yes is clicked here

MsgBox "you clicked yes"

End Sub
 

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