So che è possibile arrestare manualmente una macro VBA in esecuzione con Ctrl + Pausa, ma esiste un modo per interrompere automaticamente il codice se viene soddisfatta una determinata condizione? exit function
/exit sub
non funzionano, perché stanno solo terminando il metodo con cui sono chiamati all'interno.Come arrestare automaticamente la macro VBA?
Per esempio,
sub a
call b
msgbox "a complete"
end sub
sub b
call c
msgbox "b complete" 'this msgbox will still show after the `exit sub` in 'c'
end sub
sub c
msgbox "entering c"
exit sub 'this will only `exit sub` 'c', but not 'a' or 'b'
msgbox "exiting c"
end sub
'OUTPUT:
'entering c
'b complete
'a complete
Suppongo che potrei trasformare queste sub
's in function
' s e utilizzare i codici di ritorno per sapere se il metodo eseguito con successo, ma c'è un modo più semplice per fare questo?
Proprio come un suggerimento generale, 'goto' è male. Non usarlo –
http://stackoverflow.com/q/46586/436282 –