Subscriber only lesson.
Sign up to this course to view this lesson.
About this lesson
Identifying which button the user clicked when presented with a MsgBox in order to use their response in our code.
Download this lesson’s related exercise files.Collecting feedback from a VBA MsgBox.xlsm
26.1 KB Collecting feedback from a VBA MsgBox.xlsm
Collecting feedback from a VBA MsgBox
Continuation of user feedback and input
When to use
To continue running a macro based on which message button a user selects
- Create a Variant variable to record which button the user selects
- Test the message button selection to check the reponse
Syntax of a capture/test
Dim vAnswer As String
vAnswer = MsgBox("Message text", _
vbQuestion + vbYesNo, "Message Box Title")
If vAnswer = vbYes Then
'do something else
Hints & tips
- When setting the variable to equal a Message Box, you must include parentheses around the message and button code to capture the user’s selection
Lesson notes are only available for subscribers.