我的VBA脚本中有一个 Yes/No MsgBox ,它返回一个问题供用户回答.每当按下是"或否"按钮时,除了脚本运行其各自的代码外,还会弹出另一个带有数字"6"或"7"的 MsgBox .如何禁用第二个 MsgBox ?
I have a Yes/No MsgBoxin my VBA script that returns a question for the user to answer. Whenever the "Yes" or "No" buttons are pressed, besides the script running its respective code, another MsgBox with the numbers "6" or "7" pops up. How do I disable this second MsgBox?
这是我的代码:
Dim question As Integer question = MsgBox("Unfortunately, the Database has no sources regarding " & Category & " in " & country & ". Would you like to broaden your search and see all sources regarding " & country & "?", vbYesNo + vbQuestion, "Empty Sheet") MsgBox question If question = vbYes Then Sheets("Results").Range("D6").ClearContents Sheets("Results").Range("D7").ClearContents Category = Sheets("Results").Range("D6").Value Else Sheets("Results").Range("D5").ClearContents Sheets("Results").Range("D6").ClearContents Sheets("Results").Range("D7").ClearContents Exit Sub End If 推荐答案MsgBox 函数返回一个 vbMsgBoxResult 值,该值是一个枚举(应为 Long 整数,而不是 Integer ).
The MsgBox function returns a vbMsgBoxResult value, which is an enum (and should be a Long integer, not an Integer).
您打过两次电话:
Dim question As Integer question = MsgBox("Unfortunately, the Database has no sources regarding " & Category & " in " & country & ". Would you like to broaden your search and see all sources regarding " & country & "?", vbYesNo + vbQuestion, "Empty Sheet") MsgBox question一次分配 question ,并一次显示 question -此时将包含 vbYes (6)或 vbNo (7).
Once to assign question, and once to display question - which at that point is going to contain either vbYes (6) or vbNo (7).
我会将 question声明为vbMsgBoxResult ,以避免歧义并在以后使用它时获得autocomplete/IntelliSense.实际上, result 或 answer 会是更好的标识符-"question"听起来像问题本身,而不是用户的响应.
I would declare question As vbMsgBoxResult to avoid ambiguities and get autocomplete/IntelliSense when you later use it. Actually, result or answer would be a better identifier - "question" sounds like the question itself, not the user's response.
更多推荐
MsgBox是/否Excel VBA
发布评论