ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Determine if a userform is visible (https://www.excelbanter.com/excel-programming/448744-determine-if-userform-visible.html)

Robert Crandal[_2_]

Determine if a userform is visible
 
Is this the only way to determine if a userform is
visible? :

if (Userform.Visible = true) then
' code here
end if

The problem with this code is that it seems to automatically
run the Userform_Initialize() routine. I'm wondering how
can I detect if a userform is visible without causing the
Userform_Initialize() routine to get invoked??

Thanks








witek

Determine if a userform is visible
 
Robert Crandal wrote:
Is this the only way to determine if a userform is
visible? :

if (Userform.Visible = true) then
' code here
end if

The problem with this code is that it seems to automatically
run the Userform_Initialize() routine. I'm wondering how
can I detect if a userform is visible without causing the
Userform_Initialize() routine to get invoked??

Thanks



using "userform." will automaticaly trigger loading userform and
executing userform_initialize.

You can try that:

a) set a global variable to true in userform_initialize

b) read this http://www.ozgrid.com/forum/showthread.php?t=152892
(I did not try that just check)









GS[_2_]

Determine if a userform is visible
 
You can set a variable to a new instance of the userform and test its
existence...

Dim MyFrm As Userform
Set MyFrm = New Userform1 '//create an instance

If Not MyFrm Is Nothing Then...

...and in the case where you keep the userform loaded but not
necessarily visible...

If Not MyFrm Is Nothing Then MyFrm.Visible = True

Witek has another good suggestion that may be helpful in managing
multiple instances or a series of userforms. Though, where a series is
needed I prefer to use 'pages' on a single form because IMO it's easier
to manage multiple pages than multiple userforms<g.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion



Charlotte E.[_3_]

Determine if a userform is visible
 
A simple approach to testing if a UserForm is either loaded or visible
without actually loading the UserForm or invoking the 'UserForm_Initialize':

http://www.EXCELGAARD.dk/Lib/UserForms/UserFormState/


CE



Den 11.05.2013 11:56, Robert Crandal skrev:
Is this the only way to determine if a userform is
visible? :

if (Userform.Visible = true) then
' code here
end if

The problem with this code is that it seems to automatically
run the Userform_Initialize() routine. I'm wondering how
can I detect if a userform is visible without causing the
Userform_Initialize() routine to get invoked??

Thanks








Robert Crandal[_2_]

Determine if a userform is visible
 
"witek" wrote

You can try that:

a) set a global variable to true in userform_initialize


Hi witek..... if I set my global variable to true in
Userform_Initialize(), won't this leave the possibly of
that variable being set to true even when the userform
is NOT actually visible?

I mean, if I run the following code then the variable
will be set to true while the form is not even visible:

' This code will run Userform_Initialize and
' cause my global variable to be set to true
'
if (Userform.Visible = true) then
' My code here
end if

If I set my global variable to true in Userform_Initialize(),
should I set it to false in Userform_Terminate()?



GS[_2_]

Determine if a userform is visible
 
Use the Terminate event to reset the variable!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion



witek

Determine if a userform is visible
 
Robert Crandal wrote:
"witek" wrote

You can try that:

a) set a global variable to true in userform_initialize


Hi witek..... if I set my global variable to true in
Userform_Initialize(), won't this leave the possibly of
that variable being set to true even when the userform
is NOT actually visible?

I mean, if I run the following code then the variable
will be set to true while the form is not even visible:

' This code will run Userform_Initialize and
' cause my global variable to be set to true
'
if (Userform.Visible = true) then
' My code here
end if

If I set my global variable to true in Userform_Initialize(),
should I set it to false in Userform_Terminate()?




so do not use show. use your own code to show it at keep status somewhere.


load userform1
userform1.MyShow
unlaod userform1


and write myshow as part of userform1 with .show in it.




All times are GMT +1. The time now is 07:09 AM.

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