Msg box w/ cancel option

boxsterman

Active Member
Joined
Apr 16, 2002
Messages
279
Hi all,

I have the standard message box in my code

msgbox ("Continue?")

How do I include with with a cancel option - I want to give the user the option to abort the VBA script if they haven't completed a task.

Thanks,

J
 

Some videos you may like

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,839
Office Version
  1. 365
Platform
  1. Windows
Check out the second argument of MsgBox in VBA help, it gives you a list of options to choose, i.e.

MsgBox "Continue", vbOKCancel
will display both "OK" and "Cancel"
 

boxsterman

Active Member
Joined
Apr 16, 2002
Messages
279
Hi - thanks for the tip,

However when I press cancel, it still continues with the VBA script - I need it to cance when cancel is selected.

J.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,839
Office Version
  1. 365
Platform
  1. Windows
Here is a little script that displays how you can handle the reply:
Code:
    Dim myReply
    myReply = MsgBox("Continue", vbOKCancel)
    If myReply = vbOK Then
        MsgBox "Continuing on..."
    Else
        MsgBox "Process cancelled"
    End If
 

Watch MrExcel Video

Forum statistics

Threads
1,113,811
Messages
5,544,451
Members
410,612
Latest member
MrACED
Top