Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 如何使用Msgbox_Excel_Vba - Fatal编程技术网

Excel 如何使用Msgbox

Excel 如何使用Msgbox,excel,vba,Excel,Vba,我已经看到了很多这样做的方法,但是我是如何从vba开始的我想知道所有这样做的方法,在我可以选择我最喜欢的方式之后 我在Microsoft Oficial页面中看到了以下代码示例: Dim Msg, Style, Title, Help, Ctxt, Response, MyString Msg = "Do you want to continue ?" ' Define message. Style = vbYesNo + vbCritical + vbDefaultButton2

我已经看到了很多这样做的方法,但是我是如何从vba开始的我想知道所有这样做的方法,在我可以选择我最喜欢的方式之后

我在Microsoft Oficial页面中看到了以下代码示例:

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")


但这对我也不管用

如果您只想显示消息框,可以这样做:

Sub message()
x = MsgBox("Do you want to continue?", vbYesNo + vbCritical + vbDefaultButton2,"MsgBox Demostration ")
End Sub
在Microsoft官方示例中,您还有以下部分:

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 Sub

只有在获取返回值时才使用圆括号,如果不删除圆括号,则将其删除
x=MsgBox(…)
MsgBox…
Call MsgBox(…)
是有效的调用语法,但不是
MsgBox(…)
您没有将返回值从它设置为任何变量。上一个示例可能重复的是VB.NET。这是一种不同的语言。