在VBA中,可以使用下列代码来判断窗体是否加载:
Function IsFormLoaded(formName As String) As Boolean
Dim frm As Object
For Each frm In VBA.UserForms
If frm.Name = formName Then
IsFormLoaded = True
Exit Function
End If
Next frm
IsFormLoaded = False
End Function
使用方法如下:
Sub Test()
If IsFormLoaded("Form1") Then
MsgBox "Form1 is loaded."
Else
MsgBox "Form1 is not loaded."
End If
End Sub
在上面的示例中,如果名为"Form1"的窗体已加载,则将显示消息"Form1 is loaded.“,否则显示消息"Form1 is not loaded.”。