ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Count visible windows (https://www.excelbanter.com/excel-programming/381655-re-count-visible-windows.html)

Peter T

Count visible windows
 
Sub test()
Dim nVisCnt As Long
Dim nHiddenCnt As Long
Dim wn As Window

For Each wn In Application.Windows
If wn.Visible Then
nVisCnt = nvis.cnt + 1
Else
nHiddenCnt = nHiddenCnt + 1
End If
Next

MsgBox "Visible: " & nVisCnt & vbCr & _
"Hidden: " & nHiddenCnt, , "Windows"

End Sub

You might also want to check how many windows your own wb has in case user
did a "New Window" (which may or may not be hidden) but exclude any selected
worksheets charts is applicable.

Maybe this might be a better approach -

Sub test2()
Dim nOtherWBWindowVis As Long
Dim wn As Window
Dim wb As Workbook

For Each wb In Application.Workbooks
If wb.Name < ThisWorkbook.Name Then
For Each wn In wb.Windows
If wn.Visible Then
nOtherWBWindowVis = nOtherWBWindowVis + 1
Exit For
End If
Next
End If
Next
MsgBox "Other Visible Workbooks: " & nOtherWBWindowVis

End Sub

Yet another approach might be to loop wb's and check if any exist (even
hidden) that are not Personal.xls or "myBookName.xls"

Regards,
Peter T


"Kevin" wrote in message
...
I would like to have excel close when my workbook closes but only if there
are no other workbooks open. However depending on how many hidden

workbooks
are open the application.windows.count value will always show more than

one
workbook open.

How can I count only the visible windows and ignore things that are hidden
like personal.xls?




Peter T

Count visible windows
 
typo -

You might also want to check how many windows your own wb has in
case user did a "New Window" (which may or may not be hidden) but
exclude any selected worksheets charts is applicable.


exclude any selected worksheets charts IF applicable.

Peter T







All times are GMT +1. The time now is 03:51 PM.

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