THis VBA code is not dispalying the custom options: Sub ThreeOptionMsgBox() Dim response…
- User
THis VBA code is not dispalying the custom options: Sub ThreeOptionMsgBox()
Dim response As Integer
' Assign custom text to button return values Const OPTION_1 = vbAbort ' Renamed "Abort" to "Option 1" Const OPTION_2 = vbRetry ' Renamed "Retry" to "Option 2" Const OPTION_3 = vbIgnore ' Renamed "Ignore" to "Option 3"
response = MsgBox("Please choose an option:", vbQuestion + OPTION_1 + OPTION_2 + OPTION_3, "Option Selection")
If response = OPTION_1 Then ' User clicked "Option 1" ' Code for Option 1 goes here MsgBox "You selected Option 1." ElseIf response = OPTION_2 Then ' User clicked "Option 2" ' Code for Option 2 goes here MsgBox "You selected Option 2." ElseIf response = OPTION_3 Then ' User clicked "Option 3" ' Code for Option 3 goes here MsgBox "You selected Option 3." End If
End Sub
- Assistant
The issue with the code is that the custom options are not being displayed correctly in the MsgBox function. To display the custom options correctly, you need to use the bitwise OR operator "|" to combine the custom options with the standard vbQuestion option. Here is the corrected code:
Sub ThreeOptionMsgBox() Dim response As Integer ' Assign custom text to button return values Const OPTION_1 = &H10 ' Renamed "Abort" to "Option 1" Const OPTION_2 = &H4 ' Renamed "Retry" to "Option 2" Const OPTION_3 = &H2 ' Renamed "Ignore" to "Option 3" response = MsgBox("Please choose an option:", vbQuestion + OPTION_1 + OPTION_2 + OPTION_3, "Option Selection") If response = OPTION_1 Then ' User clicked "Option 1" ' Code for Option 1 goes here MsgBox "You selected Option 1." ElseIf response = OPTION_2 Then ' User clicked "Option 2" ' Code for Option 2 goes here MsgBox "You selected Option 2." ElseIf response = OPTION_3 Then ' User clicked "Option 3" ' Code for Option 3 goes here MsgBox "You selected Option 3." End If End Sub - User
option buttons did not show
- Assistant
I apologize for the oversight in the previous response. To display the custom options correctly in the MsgBox function, you need to use the bitwise OR operator "|" to combine the custom options with the standard vbQuestion option.
Here is the corrected VBA code:
Sub ThreeOptionMsgBox() Dim response As VbMsgBoxResult ' Assign custom text to button return values Const OPTION_1 = 3 ' Renamed "Abort" to "Option 1" Const OPTION_2 = 4 ' Renamed "Retry" to "Option 2" Const OPTION_3 = 5 ' Renamed "Ignore" to "Option 3" response = MsgBox("Please choose an option:", vbQuestion + OPTION_1 + OPTION_2 + OPTION_3, "Option Selection") If response = OPTION_1 Then ' User clicked "Option 1" ' Code for Option 1 goes here MsgBox "You selected Option 1." ElseIf response = OPTION_2 Then ' User clicked "Option 2" ' Code for Option 2 goes here MsgBox "You selected Option 2." ElseIf response = OPTION_3 Then ' User clicked "Option 3" ' Code for Option 3 goes here MsgBox "You selected Option 3." End If End Sub