显示一个警告并返回一个 Long 类型,表示用户按下的按钮。可以选择通过“Microsoft Office 助手”或普通消息框显示警告。
expression.DoAlert(bstrAlertTitle, bstrAlertText, alb, alc, ald, alq, varfSysAlert)
expression 必需。该表达式返回“应用于”列表中的对象之一。
bstrAlertTitle String 类型,必需。设置警告的标题。
bstrAlertText String 类型,必需。设置警告的文本。
alb MsoAlertButtonType 类型,必需。确定警告上显示的按钮。
MsoAlertButtonType 可以为下列 MsoAlertButtonType 常量之一。 |
msoAlertButtonAbortRetryIgnore |
msoAlertButtonOK |
msoAlertButtonOKCancel |
msoAlertButtonRetryCancel |
msoAlertButtonYesAllNoCancel 仅适用于 varfSysAlert 参数设置为 False 的情况。 |
msoAlertButtonYesNo |
msoAlertButtonYesNoCancel |
alc MsoAlertIconType 类型,必需。确定警告上显示的图标。
MsoAlertIconType 可以为下列 MsoAlertIconType 常量之一。 |
msoAlertIconCritical |
msoAlertIconInfo |
msoAlertIconNoIcon |
msoAlertIconQuery |
msoAlertIconWarning |
ald MsoAlertDefaultType 类型,必需。确定警告上的默认按钮。如果该参数的设置值大于按钮数量,将返回错误。
MsoAlertDefaultType 可以为下列 MsoAlertDefaultType 常量之一。 |
msoAlertDefaultFifth |
msoAlertDefaultFirst |
msoAlertDefaultFourth |
msoAlertDefaultSecond |
msoAlertDefaultThird |
alq MsoAlertCancelType 类型,必需。总是设置为 msoAlertCancelDefault。任何其他设置均返回错误。
MsoAlertCancelType 可以为下列 MsoAlertCancelType 常量之一。 |
msoAlertCancelDefault |
msoAlertCancelFifth |
msoAlertCancelFirst |
msoAlertCancelFourth |
msoAlertCancelSecond |
msoAlertCancelThird |
varfSysAlert Boolean 类型,必需。如果警告以消息框显示,则设置为 True,如果警告以“Office 助手”显示,则设置为 False。
DoAlert 方法的返回值对应于 vbMsgBoxResult 枚举类型的值(例如,vbYes、vbNo 或 vbCancel)。除了这些值,还可以返回下列值:
本示例通过“Office 助手”显示警告,并显示消息框指出用户按下的按钮。如果禁用了助手,则以普通消息框显示警告。
Sub AssistantAlert()
With Application.Assistant
Select Case _
.DoAlert( _
"Test", _
"Click a button.", _
msoAlertButtonYesAllNoCancel, _
msoAlertIconCritical, _
msoAlertDefaultSecond, _
msoAlertCancelFirst, _
False)
Case vbYes: MsgBox "The user clicked Yes."
Case vbNo: MsgBox "The user clicked No."
Case vbCancel: MsgBox "The user clicked Cancel."
Case 8: MsgBox "The user clicked Yes To All" 'This is the return value for YesToAll
Case Else
End Select
End With
End Sub