Is there a way to determine if a userform is hidden?
Is there a way to determine if a userform is hidden?
Use the userform.visible property. It is used to either test its status or change it.
_________________________________________________________________________
"In theory there is no difference between theory and practice. In practice there is." - Chuck Reid
Any day you learn something new is a day not wasted.
I understand the property, I think there is a difference between Hidden vs Unload. From my understanding, Hidden means its out of site, but the data on the userform can be used for other purposes. Unload means (I think) the data on the userform is lost.
Basically, I just want to know if one particular userform (AppType) is hidden.
I have this code, but it loops, therefore slows down other codes
[vba]Dim usrFrm As Object
For Each usrFrm In UserForms
If usrFrm.Name = "AppType" Then
MsgBox "Hidden"
End If
Next usrFrm
[/vba]
Last edited by av8tordude; 08-30-2012 at 03:40 AM.
Hi Aviator,
Quickly tested, but for seeing if the form is loaded, maybe:
[VBA]Option Explicit
Sub Setup1()
Load UserForm1
Load AppType
MsgBox IsLoaded("AppType")
Unload AppType
Load UserForm2
MsgBox IsLoaded("AppType")
End Sub
Function IsLoaded(UserFormName As String) As Boolean
Dim Count As Long
For Count = 0 To UserForms.Count - 1
If UserForms(Count).Name = UserFormName Then
IsLoaded = True
Exit For
End If
Next
End Function[/VBA]
For seeing if the form is loaded and showing/visible, maybe:
[VBA]Sub Setup2()
Load UserForm1
Load AppType
MsgBox IsLoadedAndHidden("AppType")
Unload AppType
Load UserForm2
MsgBox IsLoadedAndHidden("AppType")
AppType.Show vbModeless
MsgBox IsLoadedAndHidden("AppType")
AppType.Caption = "It's me!"
Dim n As Long
For n = 0 To UserForms.Count - 1
MsgBox UserForms(n).Caption
Next
End Sub
Function IsLoadedAndHidden(UserFormName As String) As Boolean
Dim Count As Long
For Count = 0 To UserForms.Count - 1
If UserForms(Count).Name = UserFormName Then
If UserForms(Count).Visible Then
IsLoadedAndHidden = True
Exit For
End If
End If
Next
End Function
[/VBA]
...see reason for editing...
Last edited by GTO; 08-30-2012 at 04:30 AM. Reason: ACK! Sorry, fumbly fingers
I should have tacked in:
The above presumes forms named:
For what it is worth, you may wish to consider prefacing (notation) your variable names. 'frmAppType' might make easier sense a few months from now (or at least make sense quicker upon reading the code), when you go back and add or edit code.
- UserForm1
- UserForm2
- AppType
BTW - you are correct as to Load(ed) vs Show(n). If your Load or Show the form, the Object Module is loaded. If you Hide the form, it still exists and any variables existing in it can still be used.
Hope that helps,
Mark
Last edited by GTO; 08-30-2012 at 04:53 AM.
If it's something you need regularly within your routine you could use an indicator (named range perhaps?) that changes state during the initialize and terminate events of the userform.
_________________________________________________________________________
"In theory there is no difference between theory and practice. In practice there is." - Chuck Reid
Any day you learn something new is a day not wasted.
Thanks you both. I think I will use the boolean procedure.