Msg box w/ cancel option

boxsterman

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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
65,492
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
283
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
65,492
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
 

Forum statistics

Threads
1,175,978
Messages
5,900,664
Members
434,842
Latest member
Kyle Bischoff

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
Top