ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Test if a Userform is loaded or activated?? (https://www.excelbanter.com/excel-programming/437105-test-if-userform-loaded-activated.html)

Robert Crandal

Test if a Userform is loaded or activated??
 
My userform only appears or activates when an event
occurs on my spreadsheet. How can I test whether
or not the Userform is currently loaded or visible??

Does the Userform object have a property or flag
I can check to see if the form is loaded??

thank u


Per Jessen

Test if a Userform is loaded or activated??
 
Hi

Use the Visible property of the userform to test if it is visible:

If Userform1.Visible=True Then
'Userform is visible
Else
'Userform is not visible
End If

Regards,
Per

"Robert Crandal" skrev i meddelelsen
...
My userform only appears or activates when an event
occurs on my spreadsheet. How can I test whether
or not the Userform is currently loaded or visible??

Does the Userform object have a property or flag
I can check to see if the form is loaded??

thank u



Peter T

Test if a Userform is loaded or activated??
 
Referring to a userform will load it into memory if it wasn't already (even
simply to test its visible property). Try something like this -

Sub test()
Dim i As Long
Dim bIsLoaded As Boolean, bIsVisible As Boolean
Dim sFrmName As String

sFrmName = "UserForm1" ' << CHANGE

For i = 1 To UserForms.Count
If UserForms(i - 1).Name = sFrmName Then
bIsLoaded = True
bIsVisible = UserForms(i - 1).Visible
Exit For
End If
Next

MsgBox bIsLoaded & vbCr & bIsVisible, , sFrmName

End Sub

Regards,
Peter T


"Per Jessen" wrote in message
...
Hi

Use the Visible property of the userform to test if it is visible:

If Userform1.Visible=True Then
'Userform is visible
Else
'Userform is not visible
End If

Regards,
Per

"Robert Crandal" skrev i meddelelsen
...
My userform only appears or activates when an event
occurs on my spreadsheet. How can I test whether
or not the Userform is currently loaded or visible??

Does the Userform object have a property or flag
I can check to see if the form is loaded??

thank u





Robert Crandal

Test if a Userform is loaded or activated??
 
How would you modify that test() function to accept
a parameter of a single userform name?? I only want to
test if a single form is loaded.

Here's the template I'm looking for:

Public Sub test (ByVal form_name as String)
'
' ???????
'
End Sub


Thank u Peter


"Peter T" <peter_t@discussions wrote in message
...
Referring to a userform will load it into memory if it wasn't already
(even simply to test its visible property). Try something like this -

Sub test()
Dim i As Long
Dim bIsLoaded As Boolean, bIsVisible As Boolean
Dim sFrmName As String

sFrmName = "UserForm1" ' << CHANGE

For i = 1 To UserForms.Count
If UserForms(i - 1).Name = sFrmName Then
bIsLoaded = True
bIsVisible = UserForms(i - 1).Visible
Exit For
End If
Next

MsgBox bIsLoaded & vbCr & bIsVisible, , sFrmName

End Sub

Regards,
Peter T


"Per Jessen" wrote in message
...
Hi

Use the Visible property of the userform to test if it is visible:

If Userform1.Visible=True Then
'Userform is visible
Else
'Userform is not visible
End If

Regards,
Per

"Robert Crandal" skrev i meddelelsen
...
My userform only appears or activates when an event
occurs on my spreadsheet. How can I test whether
or not the Userform is currently loaded or visible??

Does the Userform object have a property or flag
I can check to see if the form is loaded??

thank u






Peter T

Test if a Userform is loaded or activated??
 
If you *only* want to know if the form is loaded and not interested if it is
visible -

Function IsFormLoaded(sFrmName As String) As Boolean
Dim i As Long
Dim bIsLoaded As Boolean ' , bIsVisible As Boolean

For i = 1 To UserForms.Count
If UserForms(i - 1).Name = sFrmName Then
bIsLoaded = True
' bIsVisible = UserForms(i - 1).Visible
Exit For
End If
Next

' MsgBox bIsLoaded & vbCr & bIsVisible, , sFrmName

IsFormLoaded = bIsLoaded

End Function


to test, try simply
msgbox IsFormLoaded("UserForm1")

If you want to know if the form is visible (and by definition in must be
loaded), look at bIsVisible in the example


Regards,
Peter T


"Robert Crandal" wrote in message
...
How would you modify that test() function to accept
a parameter of a single userform name?? I only want to
test if a single form is loaded.

Here's the template I'm looking for:

Public Sub test (ByVal form_name as String)
'
' ???????
'
End Sub


Thank u Peter


"Peter T" <peter_t@discussions wrote in message
...
Referring to a userform will load it into memory if it wasn't already
(even simply to test its visible property). Try something like this -

Sub test()
Dim i As Long
Dim bIsLoaded As Boolean, bIsVisible As Boolean
Dim sFrmName As String

sFrmName = "UserForm1" ' << CHANGE

For i = 1 To UserForms.Count
If UserForms(i - 1).Name = sFrmName Then
bIsLoaded = True
bIsVisible = UserForms(i - 1).Visible
Exit For
End If
Next

MsgBox bIsLoaded & vbCr & bIsVisible, , sFrmName

End Sub

Regards,
Peter T


"Per Jessen" wrote in message
...
Hi

Use the Visible property of the userform to test if it is visible:

If Userform1.Visible=True Then
'Userform is visible
Else
'Userform is not visible
End If

Regards,
Per

"Robert Crandal" skrev i meddelelsen
...
My userform only appears or activates when an event
occurs on my spreadsheet. How can I test whether
or not the Userform is currently loaded or visible??

Does the Userform object have a property or flag
I can check to see if the form is loaded??

thank u








Rick Rothstein

Test if a Userform is loaded or activated??
 
I know in the end, it doesn't matter, but why not run your For..Next loop
between 0 and UserForms.Count-1 and then reference the "i" variable directly
in your two UserForms references? It's personal choice, of course, but it
always bothers me to directly reference to a UserForm's index using a -1
offset like that.

--
Rick (MVP - Excel)


"Peter T" <peter_t@discussions wrote in message
...
If you *only* want to know if the form is loaded and not interested if it
is visible -

Function IsFormLoaded(sFrmName As String) As Boolean
Dim i As Long
Dim bIsLoaded As Boolean ' , bIsVisible As Boolean

For i = 1 To UserForms.Count
If UserForms(i - 1).Name = sFrmName Then
bIsLoaded = True
' bIsVisible = UserForms(i - 1).Visible
Exit For
End If
Next

' MsgBox bIsLoaded & vbCr & bIsVisible, , sFrmName

IsFormLoaded = bIsLoaded

End Function


to test, try simply
msgbox IsFormLoaded("UserForm1")

If you want to know if the form is visible (and by definition in must be
loaded), look at bIsVisible in the example


Regards,
Peter T


"Robert Crandal" wrote in message
...
How would you modify that test() function to accept
a parameter of a single userform name?? I only want to
test if a single form is loaded.

Here's the template I'm looking for:

Public Sub test (ByVal form_name as String)
'
' ???????
'
End Sub


Thank u Peter


"Peter T" <peter_t@discussions wrote in message
...
Referring to a userform will load it into memory if it wasn't already
(even simply to test its visible property). Try something like this -

Sub test()
Dim i As Long
Dim bIsLoaded As Boolean, bIsVisible As Boolean
Dim sFrmName As String

sFrmName = "UserForm1" ' << CHANGE

For i = 1 To UserForms.Count
If UserForms(i - 1).Name = sFrmName Then
bIsLoaded = True
bIsVisible = UserForms(i - 1).Visible
Exit For
End If
Next

MsgBox bIsLoaded & vbCr & bIsVisible, , sFrmName

End Sub

Regards,
Peter T


"Per Jessen" wrote in message
...
Hi

Use the Visible property of the userform to test if it is visible:

If Userform1.Visible=True Then
'Userform is visible
Else
'Userform is not visible
End If

Regards,
Per

"Robert Crandal" skrev i meddelelsen
...
My userform only appears or activates when an event
occurs on my spreadsheet. How can I test whether
or not the Userform is currently loaded or visible??

Does the Userform object have a property or flag
I can check to see if the form is loaded??

thank u









Peter T

Test if a Userform is loaded or activated??
 
I'm (almost) sure I've always posted that Userforms loop exactly as you
suggest. But I was getting bored with that way so thought I'd do it
differently, just for a change <g

OK, real reason, thought it might make it a tad more understandable without
going into explanations that the index of the first loaded form, if there is
one, is 0.

Regards,
Peter T

"Rick Rothstein" wrote in message
...
I know in the end, it doesn't matter, but why not run your For..Next loop
between 0 and UserForms.Count-1 and then reference the "i" variable
directly in your two UserForms references? It's personal choice, of course,
but it always bothers me to directly reference to a UserForm's index using
a -1 offset like that.

--
Rick (MVP - Excel)


"Peter T" <peter_t@discussions wrote in message
...
If you *only* want to know if the form is loaded and not interested if it
is visible -

Function IsFormLoaded(sFrmName As String) As Boolean
Dim i As Long
Dim bIsLoaded As Boolean ' , bIsVisible As Boolean

For i = 1 To UserForms.Count
If UserForms(i - 1).Name = sFrmName Then
bIsLoaded = True
' bIsVisible = UserForms(i - 1).Visible
Exit For
End If
Next

' MsgBox bIsLoaded & vbCr & bIsVisible, , sFrmName

IsFormLoaded = bIsLoaded

End Function


to test, try simply
msgbox IsFormLoaded("UserForm1")

If you want to know if the form is visible (and by definition in must be
loaded), look at bIsVisible in the example


Regards,
Peter T


"Robert Crandal" wrote in message
...
How would you modify that test() function to accept
a parameter of a single userform name?? I only want to
test if a single form is loaded.

Here's the template I'm looking for:

Public Sub test (ByVal form_name as String)
'
' ???????
'
End Sub


Thank u Peter


"Peter T" <peter_t@discussions wrote in message
...
Referring to a userform will load it into memory if it wasn't already
(even simply to test its visible property). Try something like this -

Sub test()
Dim i As Long
Dim bIsLoaded As Boolean, bIsVisible As Boolean
Dim sFrmName As String

sFrmName = "UserForm1" ' << CHANGE

For i = 1 To UserForms.Count
If UserForms(i - 1).Name = sFrmName Then
bIsLoaded = True
bIsVisible = UserForms(i - 1).Visible
Exit For
End If
Next

MsgBox bIsLoaded & vbCr & bIsVisible, , sFrmName

End Sub

Regards,
Peter T


"Per Jessen" wrote in message
...
Hi

Use the Visible property of the userform to test if it is visible:

If Userform1.Visible=True Then
'Userform is visible
Else
'Userform is not visible
End If

Regards,
Per

"Robert Crandal" skrev i meddelelsen
...
My userform only appears or activates when an event
occurs on my spreadsheet. How can I test whether
or not the Userform is currently loaded or visible??

Does the Userform object have a property or flag
I can check to see if the form is loaded??

thank u












All times are GMT +1. The time now is 01:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com