получить все листы Excel

  • Автор темы nikh848
  • Дата начала
N

nikh848

#1
Привет всем!
Подскажите пож как правильно написать , никак не срабатывает:

Dim ВсеЛистыКниги
Dim ОткрытаяКнига

Set ОткрытаяКнига = Workbooks.Open(Путь)
ВсеЛистыКниги = ????????

For i = LBound(ВсеЛистыКниги) To UBound(ВсеЛистыКниги)
...
Next i

Как перебрать все листы, когда их количество не известно?
 

hosm

* so what *
18.05.2009
2 442
6
#2
Вот интересно, а не логично ли и быстрее найти в справке?
For i = 1 To Sheets.Count или For Each ws In Sheets
Смотря какие листы надо:
1) Все Sheets Property
Returns a Sheets collection that represents all the sheets in the active workbook, for an Application object. Returns a Sheets collection that represents all the sheets in the specified workbook, for a Workbook object. Read-only Sheets object.
The Sheets collection can contain Chart or Worksheet objects.

Remarks
For information about returning a single member of a collection, see Returning an Object from a Collection.

Using this property without an object qualifier is equivalent to using ActiveWorkbook.Sheets.

Example
This example creates a new worksheet and then places a list of the active workbook's sheet names in the first column.

Код:
Set newSheet = Sheets.Add(Type:=xlWorksheet)
For i = 1 To Sheets.Count
newSheet.Cells(i, 1).Value = Sheets(i).Name
Next i
2) Worksheets Property
For an Application object, returns a Sheets collection that represents all the worksheets in the active workbook. For a Workbook object, returns a Sheets collection that represents all the worksheets in the specified workbook. Read-only Sheets object.
Using this property without an object qualifier returns all the worksheets in the active workbook.
This property doesn’t return macro sheets; use the Excel4MacroSheets property or the Excel4IntlMacroSheets property to return those sheets.
Example
This example displays the name of each worksheet in the active workbook.
Код:
For Each ws In Worksheets
MsgBox ws.Name
Next ws
3) Charts Property
Charts Property as it applies to the Application object.
Returns a Sheets collection that represents all the chart sheets in the active workbook. Read-only.