检查用户表单是否打开 [英] Check if userform open
本文介绍了检查用户表单是否打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我运行了一个重复自身的程序.当用户关闭用户窗体时,它应该停止.它运行不停.
I run a program which repeats itself. It should stop, when the user closes the userform. It runs without stopping.
由于该程序每8秒调用一次,所以我想在最后检查用户窗体是否仍处于加载/打开状态.
Since the program calls itself every 8 seconds, I want to check at the end if the userform is still loaded / opened.
Public Sub NextPicture1()
PictureChange = Now + TimeValue("00:00:08")
If Onboarding_Projekt.Visible = True Then
Application.OnTime PictureChange, "NextPicture1"
End If
End Sub
推荐答案
您可以使用以下函数:
Public Function IsLoaded(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
用法:
If IsLoaded("Form_Test") Then
'Do Something
End If
您的代码应如下所示:
Public Sub NextPicture1()
PictureChange = Now + TimeValue("00:00:08")
If IsLoaded("Onboarding_Projekt") Then
Application.OnTime PictureChange, "NextPicture1"
End If
End Sub
Public Function IsLoaded(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
这篇关于检查用户表单是否打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文