Unload All UserForms

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.

EnvisionCAD

Since 1996, EnvisionCAD has been a nationally recognized leader in the configuration, customization, implementation, training & support for CAD software solutions. Our individualized approach has benefited private engineering firms and government agencies alike. Basic or advanced, we can help you get the most from your CAD technology.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *