View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default 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?