Worksheet Object [Excel 2003 VBA Language Reference]

Multiple objects
Worksheet
Multiple objects

Represents a worksheet. The Worksheet object is a member of the Worksheets collection. The Worksheets collection contains all the Worksheet objects in a workbook.

Using the Worksheet Object

The following properties for returning a Worksheet object are described in this section:

  • Worksheets property
  • ActiveSheet property

Worksheets Property

Use Worksheets(index), where index is the worksheet index number or name, to return a single Worksheet object. The following example hides worksheet one in the active workbook.

Worksheets(1).Visible = False

The worksheet index number denotes the position of the worksheet on the workbook's tab bar. Worksheets(1) is the first (leftmost) worksheet in the workbook, and Worksheets(Worksheets.Count) is the last one. All worksheets are included in the index count, even if they're hidden.

The worksheet name is shown on the tab for the worksheet. Use the Name property to set or return the worksheet name. The following example protects the scenarios on Sheet1.

Dim strPassword As String
strPassword = InputBox ("Enter the password for the worksheet")
Worksheets("Sheet1").Protect password:=strPassword, scenarios:=True

The Worksheet object is also a member of the Sheets collection. The Sheets collection contains all the sheets in the workbook (both chart sheets and worksheets).

ActiveSheet Property

When a worksheet is the active sheet, you can use the ActiveSheet property to refer to it. The following example uses the Activate method to activate Sheet1, sets the page orientation to landscape mode, and then prints the worksheet.

Worksheets("Sheet1").Activate
ActiveSheet.PageSetup.Orientation = xlLandscape
ActiveSheet.PrintOut

Properties | Application Property | AutoFilter Property | AutoFilterMode Property | Cells Property | CircularReference Property | CodeName Property | Columns Property | Comments Property | ConsolidationFunction Property | ConsolidationOptions Property | ConsolidationSources Property | Creator Property | CustomProperties Property | DisplayPageBreaks Property | DisplayRightToLeft Property | EnableAutoFilter Property | EnableCalculation Property | EnableOutlining Property | EnablePivotTable Property | EnableSelection Property | FilterMode Property | HPageBreaks Property | Hyperlinks Property | Index Property | ListObjects Property | MailEnvelope Property | Name Property | Names Property | Next Property | Outline Property | PageSetup Property | Parent Property | Previous Property | ProtectContents Property | ProtectDrawingObjects Property | Protection Property | ProtectionMode Property | ProtectScenarios Property | QueryTables Property | Range Property | Rows Property | Scripts Property | ScrollArea Property | Shapes Property | SmartTags Property | StandardHeight Property | StandardWidth Property | Tab Property | TransitionExpEval Property | TransitionFormEntry Property | Type Property | UsedRange Property | Visible Property | VPageBreaks Property

Methods | Activate Method | Calculate Method | ChartObjects Method | CheckSpelling Method | CircleInvalid Method | ClearArrows Method | ClearCircles Method | Copy Method | Delete Method | Evaluate Method | Move Method | OLEObjects Method | Paste Method | PasteSpecial Method | PivotTables Method | PivotTableWizard Method | PrintOut Method | PrintPreview Method | Protect Method | ResetAllPageBreaks Method | SaveAs Method | Scenarios Method | Select Method | SetBackgroundPicture Method | ShowAllData Method | ShowDataForm Method | Unprotect Method | XmlDataQuery Method | XmlMapQuery Method

Events | Activate Event | BeforeDoubleClick Event | BeforeRightClick Event | Calculate Event | Change Event | Deactivate Event | FollowHyperlink Event | PivotTableUpdate Event | SelectionChange Event

Parent Objects | HPageBreak Object | Range Collection | VPageBreak Object

Child Objects | AutoFilter Object | Comments Object | CustomProperties Object | HPageBreaks Object | Hyperlinks Object | ListObjects Object | Names Object | Outline Object | PageSetup Object | Protection Object | QueryTables Object | Range Object | Shapes Object | SmartTags Object | Tab Object | VPageBreaks Object

See Also | Controlling One Microsoft Office Application from Another | OLE Programmatic Identifiers