VBA options and warning triangle

VictorH

New Member
Joined
Jan 8, 2017
Messages
2
Hi, I have created a text message box and want to add a warning triangle to highlight the message. I tried vbExclamation but this does not work. (Nothing is added to my message) How to add the triangle please? In message box I also wanted to use the option vbYesNoCancel but this didn't work either. The box pops up correctly but clicking 'Yes' doesn't work. Seems vbOKCancel is the only option available to me. Is this correct?
 

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
10,615
Welcome to the forum.

Try:

Code:
    x = MsgBox("Do you want to continue?", vbYesNoCancel + vbExclamation, "Question")
 
Last edited:

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,371
Office Version
  1. 2019
Platform
  1. Windows
Hi Try this

Adapted from VBA helpfile

Code:
Sub MsgBoxExample()
    Dim Msg, Style, Title, Response As VbMsgBoxResult

    Msg = "Do you want to continue ?"                                          ' Define message.
    Style = vbYesNoCancel + vbExclamation + vbDefaultButton2        ' Define buttons.
    Title = "MsgBox Demonstration"                                              ' Define title.
    
'display msgbox
    Response = MsgBox(Msg, Style, Title)
'process response
    If Response = vbYes Then
'Yes Button Pressed
'do something

    ElseIf Response = vbNo Then
'No Button Pressed
'do something

    Else
'Cancel Button Pressed
'do something
        
    End If
End Sub


You can read more about MsgBox Function in VBA helpfile.

Dave
 
Last edited:

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,251
Office Version
  1. 2013
Platform
  1. Windows
If you want vbExclamation

Use this:
Code:
MsgBox("Hello", vbExclamation)

If you want Yes No Cancel
Use this:

Code:
Sub My_Message()
Dim ans As String
ans = MsgBox("Hello", vbYesNoCancel)
If ans = vbYes Then MsgBox ("You clicked Yes")
If ans = vbNo Then MsgBox ("You clicked No")
If ans = vbCancel Then MsgBox ("You clicked Cancel")
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,461
Messages
5,596,273
Members
414,049
Latest member
MisterExcel26

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top