我的结构如下:
Private Sub CreateNewQP()
If oObjectSearchResults.Count = 0 Then
Else
MsgBox "There is already QP with the same version"
End If
End Sub
然后我从Master宏调用此代码:
Sub TryToDoEverything()
On Error Resume Next
Call CreateNewQP
...
如果TryToDoEverything
出现,如何停止MsgBox "There is already QP with the same version"
?
答案 0 :(得分:2)
您可以将内部子例程更改为函数,让它返回一个值,检查所述值,如果值匹配,则退出父子例程。
类似以下的方法应该起作用:
Private Function Inner()
ResponseInner = MsgBox("I should stop outer.")
Inner = ResponseInner
End Function
Sub Outer()
Debug.Print "Calling Inner"
ResponseOuter = Inner
If ResponseOuter = 1 Then 'Should return a 1 if OK was pressed in Inner.
Exit Sub
Debug.Print "I should't print."
End If
End Sub
哪个给出以下结果:
当然,您应该正确地终止父子(如果将Application.ScreenUpdating
关闭,则将其打开,依此类推。)
答案 1 :(得分:1)