Why does Showing a UserForm as Modal Stop Code Execution?

后端 未结 5 1608
遇见更好的自我
遇见更好的自我 2020-12-16 02:29

The following VBA code stops at Me.Show. From my tests, it seems that Me.Show stops all code execution, even if the code is inside the UserForm.

相关标签:
5条回答
  • 2020-12-16 02:56

    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

    0 讨论(0)
  • 2020-12-16 03:10

    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.

    0 讨论(0)
  • 2020-12-16 03:15

    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
    
    0 讨论(0)
  • 2020-12-16 03:20

    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.

    0 讨论(0)
  • 2020-12-16 03:20

    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

    0 讨论(0)
提交回复
热议问题