Worksheets Method

Applies To

Application Object, Workbook Object.

Description

Accessor. Returns an object that represents a worksheet (a Worksheet object, Syntax 1) or a collection of all worksheets (a Worksheets object, Syntax 2) in the workbook. Read-only.

Syntax 1

object.Worksheets(index)

Syntax 2

object.Worksheets

object

Optional for Application, required for Workbook. The object that contains worksheets.

index

Required for Syntax 1. The name or number of the worksheet to return.

Remarks

This method returns worksheets with the Type property equal to xlWorksheet, not xlExcel4MacroSheet or xlExcel4IntlMacroSheet; use the Excel4MacroSheets method or the Excel4IntlMacroSheets method to return those types.

Using this method with no object qualifier is a shortcut for ActiveWorkbook.Worksheets.

Example

This example displays the value in cell A1 on Sheet1 in the active workbook.


MsgBox Worksheets("Sheet1").Range("A1").Value

This example displays the name of each worksheet in the active workbook.


For Each ws In Worksheets
    MsgBox ws.Name
Next ws

This example adds a new worksheet to the active workbook and then sets the name of the worksheet.


Set newSheet = Worksheets.Add
newSheet.Name = "1995 Budget"