温馨提示×

vba怎么判断窗体是否加载

vba
小亿
319
2023-09-15 01:22:25
栏目: 编程语言

在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.”。

0