Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 309
Default 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





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default 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








  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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










Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Constantly loaded userform?? Robert Crandal Excel Programming 1 December 6th 09 11:43 AM
Testing if Userform loaded Nigel Excel Programming 5 May 1st 07 12:55 PM
userform open when sheet activated ADK Excel Programming 11 September 7th 06 06:36 PM
Haw can i test if CTRL is activated (hold down) in VBA excelent Excel Programming 5 July 30th 06 09:44 PM
getting activated userform name x taol Excel Programming 1 January 27th 06 12:56 PM


All times are GMT +1. The time now is 08:52 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"