Testing if Userform loaded

N

Nigel

Hi All
How can I test if a userform is loaded in memory?

I have a userform that can be loaded and not visible or just not loaded.
Before I manipulate the controls on the form I need to determine if it is
memory.

Thank You
 
P

Peter T

Hi Nigel,

If UserForms.Count = 0 Then
MsgBox "no forms are loaded"
End If

Regards,
Peter T
 
N

Nigel

Hi
Thanks for the suggestion, in this case I think it will work. But I may
have more than one form and wanted something to test for a specific form
being in memory. Possible?

something like

If userform1.loaded then
do what i need to do
End If
 
P

Peter T

' for testing
' x = UserForm2.Caption ' loads if not already

If UserForms.Count > 0 Then
For i = 0 To UserForms.Count - 1
Debug.Print UserForms(i).Caption, UserForms(i).Visible
Next
End If

You could unload forms in the loop if necessary.

Regards,
Peter T
 
P

Peter T

Just to add, if unloading forms loop like this

If UserForms.Count > 0 Then
For i = UserForms.Count - 1 To 0
Unload UserForms(i)

Peter T
 
N

Nigel

Thanks - works a treat

--
Cheers
Nigel



Peter T said:
Just to add, if unloading forms loop like this

If UserForms.Count > 0 Then
For i = UserForms.Count - 1 To 0
Unload UserForms(i)

Peter T
 

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