Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: MACRO :CANCEL BUTTON

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Posts
    1,451
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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.

  2. #2
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Where is this code situated? I'm guessing that it's in a worksheet event, based upon:


    Cancel = True


    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

  3. #3
    Board Regular
    Join Date
    Mar 2002
    Posts
    1,451
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    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:


    Cancel = True


    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.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •