Why does Showing a UserForm as Modal Stop Code Execution? Why does Showing a UserForm as Modal Stop Code Execution? vba vba

Why does Showing a UserForm as Modal Stop Code Execution?


When the form is displayed with vbModal, the code will suspend execution and wait for user interaction with the form. For example clicking a button or using a dropdown.

If you update the form property

ShowModal = False

and remove vbModal from your code. This will allow code execution to continue when the form is displayed.


I was searching for an answer to why I was getting the following error:

Run time error '5': Invalid procedure call or argument

when running this line of code:

UserForm1.Show True

even though this line works:

UserForm1.Show False

Of course. True is not the same as vbModal! So the simple answer is to use the correct enumerations:

UserForm1.Show vbModalUserForm1.Show vbModeless


I think I figured this out.

After Me.Show the UserForm_Activate event fires. If there is no code in the UserForm_Activate procedure nothing will happen because VBA is waiting for Me.Hide.

So the order of events is: Me.Show > UserForm_Activate > Me.Hide

Any code that I want to run must be in the UserForm_Activate procedure and must be before Me.Hide.

The structure is very strict, but I may be able to use that structure to my advantage.