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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count of open workbooks

Status
Not open for further replies.

cg084

Technical User
May 3, 2002
67
GB
Hello,

I would have searched on this but the search is not on at the moment. I need a way to return the number of open worksheets in MS Excel.

A user will open any number of workbooks and i just need to this number to perform a loop to unprotect each of the spreadsheets open.

Thank you
 
cg084,

I may be mistaken, but you seem to be using Workbook and Worksheet interchangeably.

The open Workbooks are in the Workbooks Collection. Wach Workbook Object has a Worksheets Collection. So...
Code:
NbrWorkbooks = Workbooks.Count
Msgbox "There are " & NbrWorkbooks & " workbooks"
For Each wbk in Workbooks
  NbrWorksheets = wbk.Worksheets.Count
  Msgbox "There are " & NbrWorksheets & " worksheets in workbook " wbk.Name
Next


Skip,

[red]Be advised:[/red] [glasses]
Alcohol and Calculus do not mix!
If you drink, don't derive! [tongue]
 
Thank you for your help.

CG084
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top