Why does Showing a UserForm as Modal Stop Code Execution?

谁都会走 提交于 2019-11-30 14:00:16

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 vbModal
UserForm1.Show vbModeless
Kuyenda

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.

I think i figured it out Try doing this simple step In you form right click on the bank portion and click properties Change the "ShowModal" to False or in VBA code when you show the userform using the following code:

UserForm1.Show False

I don't really know whats going into your mind because there are a wide variety of code for what your are asking but i hope that this can help

Private Sub cmdSwitch_Click() UserForm1.Hide UserForm2.Show

End Sub

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!