我有一个VBA MsgBox
,vbYesNo
作为按钮类型,但无论按下什么按钮,它总是显示返回结果为零。对不起,这不是整个代码,但下面的代码是代码的一部分,给我带来了麻烦。
Sub testMsg()
Dim strCheckFolders As Integer ' <== vbyesno MsgBoxResult (7 = no, 6 = yes)
Dim RunThis As Boolean
RunThis = True
Do Until RunThis = False
If strCheckFolders = MsgBox("Do you want to check folders for reports to print?", _
vbYesNo, "Check for Reports to Print") = vbNo Then RunThis = False
Loop
End Sub
基本上我要做的就是在不使用标准短语if x=vbNo then Exit Sub
的情况下编写此循环。我宁愿尝试让它运行它的过程。但只有在MsgBox
可以将RunThis
的值更改为False
时,这才有效。
非常感谢任何帮助。
答案 0 :(得分:3)
=
既可用作VBA中的赋值运算符,也可用作比较运算符。您无法在单个陈述中进行分配和比较(至少在没有您获得的意外结果的情况下)。将作业与比较分开:
Do Until RunThis = False
strCheckFolders = MsgBox("Do you want to check folders for reports to print?", vbYesNo, "Check for Reports to Print")
If strCheckFolders = vbNo Then RunThis = False
Loop
您甚至可以完全取消对strCheckFolders
的需求:
Do Until RunThis = False
If MsgBox("Do you want to check folders for reports to print?", vbYesNo, _
"Check for Reports to Print") = vbNo Then RunThis = False
Loop
答案 1 :(得分:0)
我会将MsgBox放在if语句中。然后根据结果做一个动作
Do Until RunThis = False
If MsgBox("Do you want to check folders for reports to print?", vbYesNo) = vbNo Then
RunThis = False
End If
Loop
End Sub