Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I go out from a sub when another sub that is inside this sub outputs a Msgbox?

Tags:

excel

vba

Inside a sub ("Sensitivities") I am calling another sub ("MVE_NIM_Subs.MVE_Main"), if this sub outputs a MsgBox I want to end the sub and to go to the "Jump" defined, instead of continuing executing the sub. ¿How can I do it?

Thanks

Public Sub Sensitivities() 
Application.Run "MVE_NIM_Subs.MVE_Main" 
........ 
Jump: 
End Sub
like image 874
Anaa Avatar asked Jul 24 '18 10:07

Anaa


1 Answers

You can trap your Msgbox with a public boolean variable. In the sub MVE_NIM_Subs.MVE_Main modify your code to set a public boolean variable to be true if the msgbox appears.

After this sub ends, execution will go back to executing code inside sub Sensitivities. Then just check the value of the public boolean variable. If it's true, then go to Jump.

Something like this:

Option Explicit
Public DidMsg As Boolean

Sub Sensitivities()

DidMsg = False
Application.Run "MVE_NIM_Subs.MVE_Main"

If DidMsg = True Then GoTo Jump
'rest of your code
'
'
'
'


Jump:
'rest of your code after point Jump
'
'
'
'
End Sub

Sub MVE_Main()

'your code whatever it is
'right after using the msgbox type:
DidMsg = True


End Sub
like image 135
Foxfire And Burns And Burns Avatar answered Sep 29 '22 00:09

Foxfire And Burns And Burns