Message Boxes

Published on November 2, 2012

Written by Rod Wing.

Message Boxes are a means to quickly display information to the user.  Message boxes can also used to get basic Yes/No or Boolean type user input. Using Message boxes to get this kind of input can eliminate the need to develop custom UserForms to gather that information.

The MsgBox function returns a VbMsgBoxResult value which is an enumerated list with each item  corresponding the the button on the message box dialog selected by the user. The following code snippets illustrate the working with the MsgBox function to collect user input.

Dim msgResult As VbMsgBoxResult

' Display Yes and No buttons
    msgResult = MsgBox("Do you want to continue?", _
                                      vbYesNo, "My Macro")
    If msgResult = VbMsgBoxResult.vbYes Then
            'User clicked Yes button
    Else
            'User clicked No button
    End If


CAD Training

' Display OK and Cancel buttons
    msgResult = MsgBox("Do you want to continue?", _
                                   vbOKCancel, "My Macro")
    If msgResult = VbMsgBoxResult.vbOK Then
            'User clicked OK button
    Else
            'User clicked Cancel button
    End If


CAD Training

' Display Abort, Retry, and Ignore buttons
    msgResult = MsgBox("Do you want to continue?", _
                           vbAbortRetryIgnore, "My Macro")
    Select Case msgResult
        Case VbMsgBoxResult.vbAbort
            'User clicked Abort button
        Case VbMsgBoxResult.vbIgnore
            'User clicked Ignore button
        Case VbMsgBoxResult.vbRetry
            'User clicked Retry button
    End Select

 

CAD Training

 

 


Tags:
Like this article? Share it!

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Privacy Policy