Forum Discussion

cindy_lu's avatar
cindy_lu
Copper Contributor
Sep 21, 2022

Unexpected VBA Behavior: Userform showModal=False & close other Excel files make userform closed

I found that when setting the UserForm with `showModal=False` and close other excel file (not the one contains macro) will make UserForm disappear, too....

I have a long-running macro that user might still want to use Excel while the macro is executing.

It is unbelievable that the UserForm will disappear when any unrelating excel file is closed.

 

The following is a sample to reproduce it.

Just have other excel files opened, click the button in the UserForm.

Then close any other excel files will make the form disappear without any event being triggered.

I tried to catch it in `UserForm_QueryClose`, but not work.

Private Sub RunDummy_Click()
    Dim i As Long
    For i = 1 To 2000
        Application.Wait (Now + TimeValue("0:00:01"))
        Debug.Print i
        DoEvents
    Next i
End Sub

 

 

I don't think that this behavior is expected or even normal. 

How should I avoid this?

(Or is there anything wrong in my sample?

6 Replies

    • cindy_lu's avatar
      cindy_lu
      Copper Contributor

      HansVogelaar 

      I see... 

      Thanks for the suggestion. I've already sent out the problem.

      However, even if I sent out the issue, there is no promise that it will be solved right...? 

Resources