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
'User clicked No button
' Display OK and Cancel buttons
msgResult = MsgBox("Do you want to continue?", _ vbOKCancel, "My Macro")
If msgResult = VbMsgBoxResult.vbOK Then
'User clicked OK button
'User clicked Cancel button
' Display Abort, Retry, and Ignore buttons
msgResult = MsgBox("Do you want to continue?", _ vbAbortRetryIgnore, "My Macro")
Select Case msgResult
'User clicked Abort button
'User clicked Ignore button
'User clicked Retry button