Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Testing to find if UserForm is Loaded

I have multiple userforms open and hidden.

How can I test to see if a userform is loaded before attempting to either
Unload or change attributes to any controls contained therein?

thanks,

DanB
  #2   Report Post  
Excel Super Guru
 
Posts: 1,867
Thumbs up Answer: Testing to find if UserForm is Loaded

Hi DanB,

You can use the
Formula:
VBA 
function "UserForm_IsLoaded" to check if a specific userform is loaded or not. Here's an example code:
  1. If
    Formula:
    UserForm_IsLoaded 
    ("UserForm1") Then
    1. 'Do something with UserForm1 controls
    Else
    1. 'UserForm1 is not loaded
    End If

In the above code, replace "UserForm1" with the name of the userform you want to check. If the userform is loaded, the code inside the "If" block will be executed, otherwise the code inside the "Else" block will be executed.

Hope this helps! Let me know if you need further assistance.
__________________
I am not human. I am an Excel Wizard
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Testing to find if UserForm is Loaded

Why not use and If ...Then statement:

If UserForm1.Visible = True Then
'Do something
Else
UserForm1.Show
'Do something
End If


"DanB" wrote in message
...
I have multiple userforms open and hidden.

How can I test to see if a userform is loaded before attempting to either
Unload or change attributes to any controls contained therein?

thanks,

DanB



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Testing to find if UserForm is Loaded

Not quite what I'm looking for but it'd probably work.
I'll need to check if the result is different for testing both Hidden and
Unloaded Forms.

To be more specific, if I had a form that was previously Unloaded I want to
make sure that it doesn't exist before I try to Unload it again. I was
hoping that there was something as simple as an IsLoaded property, but no
such luck.

If there's another way of detecting, I'm all ears!

Best,
DB

"JLGWhiz" wrote:

Why not use and If ...Then statement:

If UserForm1.Visible = True Then
'Do something
Else
UserForm1.Show
'Do something
End If


"DanB" wrote in message
...
I have multiple userforms open and hidden.

How can I test to see if a userform is loaded before attempting to either
Unload or change attributes to any controls contained therein?

thanks,

DanB




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Testing to find if UserForm is Loaded

If it is hidden you can use the Show method to make it visible. Show also
will invoke Load so in either case, the Show method will make the form
visible. Testing if it is visible will tell you if it is in a state that
you can unload.

If you are thinking of running a loop to test for the status of each
UserForm, it could be problematic in that if the form is loaded modal, it
must be unloaded to proceed to further code execution in the calling
procedure. If it is loaded modeless, I don't know of a criteria to check
for the hidden forms except by name or whethere it is visible/hidden. To
check by name would probably entail making an array of names to loop
against. Anyhow, the visible property seemed the easiest way to me.


"DanB" wrote in message
...
Not quite what I'm looking for but it'd probably work.
I'll need to check if the result is different for testing both Hidden and
Unloaded Forms.

To be more specific, if I had a form that was previously Unloaded I want
to
make sure that it doesn't exist before I try to Unload it again. I was
hoping that there was something as simple as an IsLoaded property, but no
such luck.

If there's another way of detecting, I'm all ears!

Best,
DB

"JLGWhiz" wrote:

Why not use and If ...Then statement:

If UserForm1.Visible = True Then
'Do something
Else
UserForm1.Show
'Do something
End If


"DanB" wrote in message
...
I have multiple userforms open and hidden.

How can I test to see if a userform is loaded before attempting to
either
Unload or change attributes to any controls contained therein?

thanks,

DanB








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Testing to find if UserForm is Loaded

Just tested, it .visible comes up False for both states of Hidden or Unloaded.

I guess I'll need to create public flag variables and create code to track
when I load/unload forms.

Thanks for trying,

DB

"JLGWhiz" wrote:

If it is hidden you can use the Show method to make it visible. Show also
will invoke Load so in either case, the Show method will make the form
visible. Testing if it is visible will tell you if it is in a state that
you can unload.

If you are thinking of running a loop to test for the status of each
UserForm, it could be problematic in that if the form is loaded modal, it
must be unloaded to proceed to further code execution in the calling
procedure. If it is loaded modeless, I don't know of a criteria to check
for the hidden forms except by name or whethere it is visible/hidden. To
check by name would probably entail making an array of names to loop
against. Anyhow, the visible property seemed the easiest way to me.


"DanB" wrote in message
...
Not quite what I'm looking for but it'd probably work.
I'll need to check if the result is different for testing both Hidden and
Unloaded Forms.

To be more specific, if I had a form that was previously Unloaded I want
to
make sure that it doesn't exist before I try to Unload it again. I was
hoping that there was something as simple as an IsLoaded property, but no
such luck.

If there's another way of detecting, I'm all ears!

Best,
DB

"JLGWhiz" wrote:

Why not use and If ...Then statement:

If UserForm1.Visible = True Then
'Do something
Else
UserForm1.Show
'Do something
End If


"DanB" wrote in message
...
I have multiple userforms open and hidden.

How can I test to see if a userform is loaded before attempting to
either
Unload or change attributes to any controls contained therein?

thanks,

DanB






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Testing to find if UserForm is Loaded

I think this function will do what you want, just pass it the name of the
UserForm...

Function IsUserFormLoaded(UserFormName As String) As Boolean
Dim UF As Object
For Each UF In UserForms
If UCase(UF.Name) = UCase(UserFormName) Then
IsUserFormLoaded = True
Exit Function
End If
Next
End Function

--
Rick (MVP - Excel)


"DanB" wrote in message
...
Just tested, it .visible comes up False for both states of Hidden or
Unloaded.

I guess I'll need to create public flag variables and create code to track
when I load/unload forms.

Thanks for trying,

DB

"JLGWhiz" wrote:

If it is hidden you can use the Show method to make it visible. Show
also
will invoke Load so in either case, the Show method will make the form
visible. Testing if it is visible will tell you if it is in a state that
you can unload.

If you are thinking of running a loop to test for the status of each
UserForm, it could be problematic in that if the form is loaded modal, it
must be unloaded to proceed to further code execution in the calling
procedure. If it is loaded modeless, I don't know of a criteria to check
for the hidden forms except by name or whethere it is visible/hidden. To
check by name would probably entail making an array of names to loop
against. Anyhow, the visible property seemed the easiest way to me.


"DanB" wrote in message
...
Not quite what I'm looking for but it'd probably work.
I'll need to check if the result is different for testing both Hidden
and
Unloaded Forms.

To be more specific, if I had a form that was previously Unloaded I
want
to
make sure that it doesn't exist before I try to Unload it again. I was
hoping that there was something as simple as an IsLoaded property, but
no
such luck.

If there's another way of detecting, I'm all ears!

Best,
DB

"JLGWhiz" wrote:

Why not use and If ...Then statement:

If UserForm1.Visible = True Then
'Do something
Else
UserForm1.Show
'Do something
End If


"DanB" wrote in message
...
I have multiple userforms open and hidden.

How can I test to see if a userform is loaded before attempting to
either
Unload or change attributes to any controls contained therein?

thanks,

DanB







  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Testing to find if UserForm is Loaded

Rick,

This was exactly what I was looking for.

Thank you very much!

Best,

Dan

"Rick Rothstein" wrote:

I think this function will do what you want, just pass it the name of the
UserForm...

Function IsUserFormLoaded(UserFormName As String) As Boolean
Dim UF As Object
For Each UF In UserForms
If UCase(UF.Name) = UCase(UserFormName) Then
IsUserFormLoaded = True
Exit Function
End If
Next
End Function

--
Rick (MVP - Excel)


"DanB" wrote in message
...
Just tested, it .visible comes up False for both states of Hidden or
Unloaded.

I guess I'll need to create public flag variables and create code to track
when I load/unload forms.

Thanks for trying,

DB

"JLGWhiz" wrote:

If it is hidden you can use the Show method to make it visible. Show
also
will invoke Load so in either case, the Show method will make the form
visible. Testing if it is visible will tell you if it is in a state that
you can unload.

If you are thinking of running a loop to test for the status of each
UserForm, it could be problematic in that if the form is loaded modal, it
must be unloaded to proceed to further code execution in the calling
procedure. If it is loaded modeless, I don't know of a criteria to check
for the hidden forms except by name or whethere it is visible/hidden. To
check by name would probably entail making an array of names to loop
against. Anyhow, the visible property seemed the easiest way to me.


"DanB" wrote in message
...
Not quite what I'm looking for but it'd probably work.
I'll need to check if the result is different for testing both Hidden
and
Unloaded Forms.

To be more specific, if I had a form that was previously Unloaded I
want
to
make sure that it doesn't exist before I try to Unload it again. I was
hoping that there was something as simple as an IsLoaded property, but
no
such luck.

If there's another way of detecting, I'm all ears!

Best,
DB

"JLGWhiz" wrote:

Why not use and If ...Then statement:

If UserForm1.Visible = True Then
'Do something
Else
UserForm1.Show
'Do something
End If


"DanB" wrote in message
...
I have multiple userforms open and hidden.

How can I test to see if a userform is loaded before attempting to
either
Unload or change attributes to any controls contained therein?

thanks,

DanB








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
Cannot find a loaded VBA addin Simon Reid[_2_] Excel Programming 3 October 3rd 09 12:32 AM
Testing if Userform loaded Nigel Excel Programming 5 May 1st 07 12:55 PM
Extracting Colors from Image loaded in userform emsfeld Excel Programming 6 June 4th 04 04:05 PM
Excel: VBA userform is shown but not loaded/initialized even though it was first unloaded? Luisa[_2_] Excel Programming 2 December 5th 03 08:15 AM
Detecting if a userform is loaded Seth[_5_] Excel Programming 2 November 4th 03 02:59 AM


All times are GMT +1. The time now is 02:23 AM.

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

About Us

"It's about Microsoft Excel"