MACRO :CANCEL BUTTON

verluc

Well-known Member
Joined
Mar 1, 2002
Messages
1,451
I have the following macro:

Dim olApp As Object, olMail As Object
Dim rngeAddresses As Range, rngeCell As Range
Set olApp = CreateObject("Outlook.Application")
intResponse = MsgBox(prompt:=".....", _
Buttons:=vbQuestion + vbYesNoCancel
On Error Resume Next
Select Case intResponse
Case vbYes
Set rngeAddresses = range("...")
Case vbNo
Set rngeAddresses = Application.InputBox(prompt:="........"
Case vbCancel
Cancel = True
End Select
On Error GoTo 0
For Each rngeCell In rngeAddresses.Cells
Set olMail = olApp.CreateItem
olMail.To = rngeCell.Value
Next

Why the button "Cancel" doesn't work,because I become an error?
Thanks for help.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Where is this code situated? I'm guessing that it's in a worksheet event, based upon:

<pre>
Cancel = True </pre>

I would suggest using "Exit Sub" instead of Cancel = True, assuming that all you want to do is to stop the sub routine should the user choose to "Cancel".

HTH
 
Upvote 0
On 2002-04-29 12:24, Mark O'Brien wrote:
Where is this code situated? I'm guessing that it's in a worksheet event, based upon:

<pre>
Cancel = True </pre>

I would suggest using "Exit Sub" instead of Cancel = True, assuming that all you want to do is to stop the sub routine should the user choose to "Cancel".

HTH
Hi Mark, great it works now.
Many thanks for your time.
 
Upvote 0

Forum statistics

Threads
1,214,402
Messages
6,119,299
Members
448,885
Latest member
LokiSonic

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