MsgBox And DV Error Alert Icons - Excel At Finance
Có thể bạn quan tâm
0. Quick guide
The VBA MsgBox() function allows a choice of an optional icon from a list of four. The icon is displayed to the left of the Prompt.
Icons are part of the Buttons arguments as type VbMsgBoxStyle enumerations with default value 0 (vbOkOnly)
1. The MsgBox() function and VbMsgBoxStyle enumerations
- The MsgBox function Quick Info lists the arguments
- MsgBox(Prompt, [Buttons As VbMsgBoxStyle = vbOKOnly],[Title],[HelpFile],[Context]) As VbMsgBoxResult
- The VbMsgBoxStyle enumerations include four enumerated constants (16, 32, 48 and 64) for icons:
- vbCritical (16)
- vbQuestion (32)
- vbExclamation (48)
- vbInformation (64)
- Icon images are shown in the next section
2. MsgBox enumerated constant icons
Icons are optional. The MsgBox function can display a maximum of one icons from the list.
| Icon | Constant (value) | Description |
|---|---|---|
| | vbCritical (16) | Displays the Critical Message icon - stop sign |
| | vbQuestion (32) | Displays the Warning Query icon - a question mark |
| | vbExclamation (48) | Displays the Warning Message icon - an exclamation point |
| | vbInformation (64) | Displays the Information Message icon |
The names of the constants are displayed in the VbMsgBoxStyle Quick Info list (figure 1).

3. Data validation Error Alert Style icons
The Excel data validation tool allows the user to compose a custom message box from properties on the Data Validation > Error Alert tab (see figure 2). Three icons are available. The MsgBox vbQuestion icon has been dropped from the list.

| Icon | Style AlertStyle (value) | Description |
|---|---|---|
| | Stop xlValidAlertStop (1) | Displays the Stop icon |
| | Warning xlValidAlertWarning (2) | Displays the Warning icon - an exclamation point |
| | Information xlValidAlertInformation (3) | Displays the Information icon |

The message boxes from MsgBox() function, and the Data Validation Error Alert are compared in figure 3.
- Development platform: Excel 2016 (64 bit) Office 365 ProPlus and VBA 7.1
- Published: 3 October 2017
- Revised: Saturday 25th of February 2023 - 10:12 AM, [Australian Eastern Time (AET)]
Từ khóa » Visual Basic Msgbox Icon
-
MsgBox Function (Visual Basic For Applications) | Microsoft Docs
-
MessageBoxIcon Enum (System.Windows.Forms) - Microsoft Docs
-
Excel VBA MsgBox [Message Box] - All You Need To Know!
-
Buttons And Icons In The MsgBox Function
-
VBA Put An Icon On Msgbox (Exclamation, Question Mark ... - YouTube
-
How To Create Message Box Icon,Button And Headline In Visual Basic
-
How To Add A Custom Icon To MessageBox? - Stack Overflow
-
Yes No Message Box (Msgbox) - VBA Code Examples
-
Giới Thiệu Hàm MsgBox Trong Visual Basic - WordPress Developer
-
Sử Dụng MsgBox Trong Excel VBA - Hướng Dẫn đầy đủ
-
MessageBox Function In Visual Basic 6 (VB6)
-
VBA MsgBox Excel Examples - 100+ Message Box Macros
-
Thread: Change The Message Box Default Icon - VBForums