How to have VBA code wait until vbModeless userform is closed

后端 未结 3 1310
终归单人心
终归单人心 2021-02-11 02:38

I\'d like to use a formless userform so the user can navigate the excel sheet before answering the question on the userform. I need to pause or loop the code until the userform

3条回答
  •  伪装坚强ぢ
    2021-02-11 03:19

    I didn't author the following function, but I have used it for a long time and it works.

    Private Function IsLoaded(ByVal formName As String) As Boolean
        Dim frm As Object
        For Each frm In VBA.UserForms
            If frm.Name = formName Then
                IsLoaded = True
                Exit Function
            End If
        Next frm
        IsLoaded = False
    End Function
    

    You will need to hardcode the string name, and not use the .Name property of the form because the form may not be loaded yet and not contain this property.

    Here is a small snippet of how you can use this function:

    Do While IsLoaded("StartingSINT_Popup")
        Debug.Print Time; " StartingSINT_Popup Is Loaded!"
    Loop
    

提交回复
热议问题