我已经看过很多方法来做到这一点,但是我想知道如何开始使用vba,因为在我可以选择我最喜欢的方式之后,我想知道所有的方法。
我在Microsoft Oficcial页面上看到了这个代码示例:
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Do you want to continue ?" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "MsgBox Demonstration" ' Define title.
Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)我想做同样的事情,但是没有变量,我的意思是,这是:
MsgBox("Do you want to continue?", vbYesNo + vbCritical + vbDefaultButton2,"MsgBox Demostration ")但这返回了一个错误,我认为这个例子和我做的完全一样,但是没有变量,所以我不知道为什么它不起作用。
我看到另一个人在做这个:
MsgBox("Do you want to continue?",msgboxstyle.vbYesNo,"tittle")但这对我也不起作用。
发布于 2019-08-21 18:48:23
如果你只想显示消息框,你可以这样做:
Sub message()
x = MsgBox("Do you want to continue?", vbYesNo + vbCritical + vbDefaultButton2,"MsgBox Demostration ")
End Sub在微软官方的例子中,你也有这个部分:
If Response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
Else ' User chose No.
MyString = "No" ' Perform some action.
End If如果你想在有人点击“是”或“否”时发生任何事情,你需要在这里包括它。
例如,在您的示例中:
Sub message()
If MsgBox("Do you want to continue?", vbYesNo + vbCritical + vbDefaultButton2,"MsgBox Demostration ") = vbYes Then
'any action you would like it to perform if yes
Else
'any action you would like it to perform if no
End If
End Subhttps://stackoverflow.com/questions/57589330
复制相似问题