ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Code, is user form open (https://www.excelbanter.com/excel-programming/375205-code-user-form-open.html)

Excel 2003 - SPB

Code, is user form open
 
I am trying to find code for indentifying if a user form is open

Thanks

SPB

Tom Ogilvy

Code, is user form open
 
for each frm in Userforms
if lcase(frm.name) = "frmabc" then
' frm is loaded
if frm.visible then
' frm is visible
end if
end if
Next

Obviously if the useform isn't loaded, then it can't be visible.

--
Regards,
Tom Ogilvy


"Excel 2003 - SPB" wrote:

I am trying to find code for indentifying if a user form is open

Thanks

SPB


Excel 2003 - SPB

Code, is user form open
 
More Details
I have two forms (of many) [flightlog & maintenance] and I need to identify
which one is open (only one at a time) then are always visible or closed.

"Tom Ogilvy" wrote:

for each frm in Userforms
if lcase(frm.name) = "frmabc" then
' frm is loaded
if frm.visible then
' frm is visible
end if
end if
Next

Obviously if the useform isn't loaded, then it can't be visible.

--
Regards,
Tom Ogilvy


"Excel 2003 - SPB" wrote:

I am trying to find code for indentifying if a user form is open

Thanks

SPB


Tom Ogilvy

Code, is user form open
 
Play with this:

Sub abc()
Dim frm As Object, frm1 As Object
If UserForms.Count 0 Then
For Each frm In useforms
Unload frm
Next
End If
If Rnd() < 0.5 Then
Load maintenance
maintenance.Show vbModeless
Else
Load flightlog
flightlog.Show vbModeless
End If


namevis = ""
Set frm1 = Nothing
For Each frm In UserForms
Debug.Print TypeName(frm)
If LCase(frm.Name) = "flightlog" Then
If frm.Visible Then
namevis = "flightlog"
Set frm1 = frm
Exit For
End If
ElseIf LCase(frm.Name) = "maintenance" Then
If frm.Visible Then
namevis = "maintenance"
Set frm1 = frm
Exit For
End If
End If
Next
If Not frm1 Is Nothing Then
MsgBox namevis & " is the open form"
End If
Unload frm1
End Sub

--
Regards,
Tom Ogilvy


"Excel 2003 - SPB" wrote:

More Details
I have two forms (of many) [flightlog & maintenance] and I need to identify
which one is open (only one at a time) then are always visible or closed.

"Tom Ogilvy" wrote:

for each frm in Userforms
if lcase(frm.name) = "frmabc" then
' frm is loaded
if frm.visible then
' frm is visible
end if
end if
Next

Obviously if the useform isn't loaded, then it can't be visible.

--
Regards,
Tom Ogilvy


"Excel 2003 - SPB" wrote:

I am trying to find code for indentifying if a user form is open

Thanks

SPB


Excel 2003 - SPB

Code, is user form open
 
Thanks tom
I added another elseif for one other area i had not thought about and all is
good

Thanks
SPB

"Tom Ogilvy" wrote:

Play with this:

Sub abc()
Dim frm As Object, frm1 As Object
If UserForms.Count 0 Then
For Each frm In useforms
Unload frm
Next
End If
If Rnd() < 0.5 Then
Load maintenance
maintenance.Show vbModeless
Else
Load flightlog
flightlog.Show vbModeless
End If


namevis = ""
Set frm1 = Nothing
For Each frm In UserForms
Debug.Print TypeName(frm)
If LCase(frm.Name) = "flightlog" Then
If frm.Visible Then
namevis = "flightlog"
Set frm1 = frm
Exit For
End If
ElseIf LCase(frm.Name) = "maintenance" Then
If frm.Visible Then
namevis = "maintenance"
Set frm1 = frm
Exit For
End If
End If
Next
If Not frm1 Is Nothing Then
MsgBox namevis & " is the open form"
End If
Unload frm1
End Sub

--
Regards,
Tom Ogilvy


"Excel 2003 - SPB" wrote:

More Details
I have two forms (of many) [flightlog & maintenance] and I need to identify
which one is open (only one at a time) then are always visible or closed.

"Tom Ogilvy" wrote:

for each frm in Userforms
if lcase(frm.name) = "frmabc" then
' frm is loaded
if frm.visible then
' frm is visible
end if
end if
Next

Obviously if the useform isn't loaded, then it can't be visible.

--
Regards,
Tom Ogilvy


"Excel 2003 - SPB" wrote:

I am trying to find code for indentifying if a user form is open

Thanks

SPB



All times are GMT +1. The time now is 06:27 AM.

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