Detecting if a userform is loaded

J

jaf

Hi Seth,
If userform1 is nothing then msgbox "Form Not Loaded"
Or
If not userform1 is nothing then msgbox "Form Is Loaded"
 
T

Tom Ogilvy

as soon as you reference Userform1 in your code, if it isn't loaded, it gets
loaded. So Johns code would always show it is loaded.

You can check the userforms collection

Sub tester4()
Dim bLoaded as boolean
Dim frm
'Load UserForm1
For Each frm In UserForms
If UCase(frm.Name) = UCase("UserForm1") Then
MsgBox "Userform1 is loaded"
bLoaded = True
Exit For
End If
Next
If Not bLoaded Then
MsgBox "Userform1 is not loaded"
End If

End Sub

Run as is, then
Uncomment Load UserForm1
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top