消息框在Excel VBA
在本文中,我们将学习Excel VBA中的MsgBox函数,以下是msgbox vba的按钮参数设置:
Constant |
Value |
Description |
vbOKOnly |
0 |
Display OK button only. |
vbOKCancel |
1 |
Display OK and Cancel buttons. |
vbAbortRetryIgnore |
2 |
Display Abort, Retry, and Ignore buttons. |
vbYesNoCancel |
3 |
Display Yes, No, and Cancel buttons. |
vbYesNo |
4 |
Display Yes and No buttons. |
vbRetryCancel |
5 |
Display Retry and Cancel buttons. |
vbCritical |
16 |
Display Critical Message icon. |
vbQuestion |
32 |
Display Warning Query icon. |
vbExclamation |
48 |
Display Warning Message icon. |
vbInformation |
64 |
Display Information Message icon. |
vbDefaultButton1 |
0 |
First button is default. |
vbDefaultButton2 |
256 |
Second button is default. |
vbDefaultButton3 |
512 |
Third button is default. |
vbDefaultButton4 |
768 |
Fourth button is default. |
vbApplicationModal |
0 |
Application modal; the user must respond to the message box before continuing work in the current application. |
vbSystemModal |
4096 |
System modal; all applications are suspended until the user responds to the message box. |
vbMsgBoxHelpButton |
16384 |
Adds Help button to the message box |
VbMsgBoxSetForeground |
65536 |
Specifies the message box window as the foreground window |
vbMsgBoxRight |
524288 |
Text is right aligned |
vbMsgBoxRtlReading |
1048576 |
Specifies text should appear as right-to-left reading on Hebrew and Arabic systems |
让我们看看vba消息框如何帮助用户删除当前工作表中单元格的所有内容。
以下是数据的快照:
我们需要执行以下步骤:
单击“开发人员”选项卡。从“代码”组中,选择“ Visual Basic”
-
让我们插入一个命令按钮
-
在当前工作表模块中输入以下代码:-
| ===显式选项
私人子CommandButton1_Click()
答案为整数
答案= MsgBox(“是否要删除当前工作表中的所有单元格?”,vbYesNo + vbQuestion,“删除所有单元格”)
如果答案= vbYes那么
Cells.ClearContents
其他
‘不执行
如果
结束
结束子
-
单击“命令”按钮时,将出现以下提示
-
单击是按钮删除所有单元格。
-
结果如下
这样,我们可以使用Excel VBA中的命令按钮删除所有单元格。