Consulting

Results 1 to 2 of 2

Thread: Exit MsgBox If MsgBoxResult = Cancel

  1. #1

    Exit MsgBox If MsgBoxResult = Cancel

    Hi, I have a code which I'm trying to get to exit the sub if the user clicks cancel on the message box or activate a different worksheet if they click ok.

    For some reason it activates the sheet no matter what button I press.

    Sub ScopeofWorkInstructions()
    
    
    MsgBox "                                             SCOPE OF WORK INSTRUCTIONS:" _
    & vbNewLine & " " _
    & vbNewLine & "1. Please fill out as much information as possible." _
    & vbNewLine & " " _
    & vbNewLine & "2. Use the Notes column for additional information discussed." _
    & vbNewLine & " " _
    & vbNewLine & "3. Download the Client's Logo and insert it as a picture sized to fit within the logo box." _
    & vbNewLine & " " _
    & vbNewLine & "4. Please return to the Navigation and check the completion box when finished." _
    , vbOKCancel
    If MsgBoxResult = vbCancel Then
    Exit Sub
    Else
    Set ws = Worksheets("Scope of Work")
    ws.Activate
    End If
    
    
    End Sub
    Any idea why?

  2. #2
    Because your message box isn't using "MsgBoxResult".
    So therefore it's "Empty". Which will result in the ELSE tag.

    This will fix it.

    Sub ScopeofWorkInstructions()
    
    
    
    MsgBoxResult = MsgBox("                                             SCOPE OF WORK INSTRUCTIONS:" _
    & vbNewLine & " " _
    & vbNewLine & "1. Please fill out as much information as possible." _
    & vbNewLine & " " _
    & vbNewLine & "2. Use the Notes column for additional information discussed." _
    & vbNewLine & " " _
    & vbNewLine & "3. Download the Client's Logo and insert it as a picture sized to fit within the logo box." _
    & vbNewLine & " " _
    & vbNewLine & "4. Please return to the Navigation and check the completion box when finished." _
    , vbOKCancel)
    
    
    If MsgBoxResult = vbCancel Then
    Exit Sub
    Else
    Set ws = Worksheets("Scope of Work")
    ws.Activate
    End If

Posting Permissions

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