Msg box w/ cancel option

boxsterman

Active Member
Joined
Apr 16, 2002
Messages
285
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
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
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"
 
Upvote 0
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.
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,595
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top