UserForms in VBA are the primary way to gather user input required for your macro. More complex macros may require the loading and unloading of multiple forms for gathering different types of input, particularly if you are trying to create a “wizard” type of interface. Managing the showing, hiding, and unloading of forms for multi-form macros can be a challenge.
This is particularly true when trying to exit a macro. A VBA macro will continue executing if there is a UserForm loaded. The simple Sub displayed below will unload every UserForm your macro has loaded.
Sub UnloadAllForms()
Dim myForm As UserForm
For Each myForm In UserForms
Unload myForm
Next
End Sub
This code snippet would be a very useful addition to an ExitMacro routine as discussed in other VBA tips.