Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel97 VBA: How can I count open workbooks that are not hidden?

Status
Not open for further replies.

BarryG

Programmer
Nov 19, 1999
23
0
0
US
In a function I'm writing, I need to find the number of open workbooks, but I want to exclude those that are hidden. Please help!<br>
<br>
Thanks<br>
Barry
 
Hi Barryg<br>
<br>
As you probably know there is no method to count visible workbooks. However, try this routine and I hope it works<br>
<br>
<br>
Sub VisibleWorkbooks()<br>
'Count the number of Open Workbooks<br>
vopenworkbooks = Application.Windows.Count<br>
vvisible = 0<br>
'Loop to check is the workbook hidden<br>
For counter = 1 To vopenworkbooks<br>
If Windows(counter).Visible = True Then vvisible = vvisible + 1<br>
Next<br>
MsgBox (&quot;the Number of Workbooks open and not hidden is &quot; & vvisible)<br>
<br>
End Sub<br>
<br>
<br>
Let me know how you get on!!<br>
<br>
Regards<br>
Monica
 
Thanks, Monica. It worked well. I was stuck because visible wasn't a valid property of the workbooks collection and I didn't know about the Windows collection. I'm very new to VBA in Excel so it's taking a while to learn to collection, properties, methods, etc.<br>
<br>
Thanks again,<br>
Barry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top