Sheets Property

Microsoft Office Web Components Object Model

Show All

Sheets Property

       

Sheets property as it applies to the Spreadsheet object.

Returns a Sheets collection that represents all the sheets in the active workbook.

expression.Sheets

expression   Required. An expression that returns a Spreadsheet object.

Sheets property as it applies to the Workbook object.

Returns a Sheets collection that represents all the sheets in the specified workbook.

expression.Sheets

expression   Required. An expression that returns a Workbook object.

Example

As it applies to the Workbook object.

This example sorts the worksheets in the active workbook of Spreadsheet1 in ascending order.

Sub Sort_Sheets()
   Dim i
   Dim j
   Dim iSheetCount

   iSheetCount = Spreadsheet1.ActiveWorkbook.Sheets.Count

   For i = 1 To iSheetCount
      For j = 1 To iSheetCount - 1
         If UCase(Spreadsheet1.ActiveWorkbook.Sheets(j).Name) > _
            UCase(Spreadsheet1.ActiveWorkbook.Sheets(j + 1).Name) Then

             Spreadsheet1.ActiveWorkbook.Sheets(j).Move , _
                Spreadsheet1.ActiveWorkbook.Sheets(j + 1)
         End If
      Next
   Next
End Sub