Workbook Object [Excel 2003 VBA Language Reference]

Multiple objects
Workbook
Multiple objects

Represents a Microsoft Excel workbook. The Workbook object is a member of the Workbooks collection. The Workbooks collection contains all the Workbook objects currently open in Microsoft Excel.

Using the Workbook Object

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

  • Workbooks property
  • ActiveWorkbook property
  • ThisWorkbook property

Workbooks Property

Use Workbooks(index), where index is the workbook name or index number, to return a single Workbook object. The following example activates workbook one.

Workbooks(1).Activate

The index number denotes the order in which the workbooks were opened or created. Workbooks(1) is the first workbook created, and Workbooks(Workbooks.Count) is the last one created. Activating a workbook doesn't change its index number. All workbooks are included in the index count, even if they're hidden.

The Name property returns the workbook name. You cannot set the name by using this property; if you need to change the name, use the SaveAs method to save the workbook under a different name. The following example activates Sheet1 in the workbook named Cogs.xls (the workbook must already be open in Microsoft Excel).

Workbooks("Cogs.xls").Worksheets("Sheet1").Activate

ActiveWorkbook Property

The ActiveWorkbook property returns the workbook that's currently active. The following example sets the name of the author for the active workbook.

ActiveWorkbook.Author = "Jean Selva"

ThisWorkbook Property

The ThisWorkbook property returns the workbook where the Visual Basic code is running. In most cases, this is the same as the active workbook. However, if the Visual Basic code is part of an add-in, the ThisWorkbook property won't return the active workbook. In this case, the active workbook is the workbook calling the add-in, whereas the ThisWorkbook property returns the add-in workbook.

If you'll be creating an add-in from your Visual Basic code, you should use the ThisWorkbook property to qualify any statement that must be run on the workbook you compile into the add-in.

Properties | AcceptLabelsInFormulas Property | ActiveChart Property | ActiveSheet Property | Application Property | AutoUpdateFrequency Property | AutoUpdateSaveChanges Property | BuiltinDocumentProperties Property | CalculationVersion Property | ChangeHistoryDuration Property | Charts Property | CodeName Property | Colors Property | CommandBars Property | ConflictResolution Property | Container Property | CreateBackup Property | Creator Property | CustomDocumentProperties Property | CustomViews Property | Date1904 Property | DisplayDrawingObjects Property | DisplayInkComments Property | DocumentLibraryVersions Property | EnableAutoRecover Property | EnvelopeVisible Property | Excel4IntlMacroSheets Property | Excel4MacroSheets Property | FileFormat Property | FullName Property | FullNameURLEncoded Property | HasPassword Property | HasRoutingSlip Property | HighlightChangesOnScreen Property | HTMLProject Property | InactiveListBorderVisible Property | IsAddin Property | IsInPlace Property | KeepChangeHistory Property | ListChangesOnNewSheet Property | Mailer Property | MultiUserEditing Property | Name Property | Names Property | Parent Property | Password Property | PasswordEncryptionAlgorithm Property | PasswordEncryptionFileProperties Property | PasswordEncryptionKeyLength Property | PasswordEncryptionProvider Property | Path Property | Permission Property | PersonalViewListSettings Property | PersonalViewPrintSettings Property | PrecisionAsDisplayed Property | ProtectStructure Property | ProtectWindows Property | PublishObjects Property | ReadOnly Property | ReadOnlyRecommended Property | RemovePersonalInformation Property | RevisionNumber Property | Routed Property | RoutingSlip Property | Saved Property | SaveLinkValues Property | SharedWorkspace Property | Sheets Property | ShowConflictHistory Property | ShowPivotTableFieldList Property | SmartDocument Property | SmartTagOptions Property | Styles Property | Sync Property | TemplateRemoveExtData Property | UpdateLinks Property | UpdateRemoteReferences Property | UserStatus Property | VBASigned Property | VBProject Property | WebOptions Property | Windows Property | Worksheets Property | WritePassword Property | WriteReserved Property | WriteReservedBy Property | XmlMaps Property | XmlNamespaces Property

Methods | AcceptAllChanges Method | Activate Method | AddToFavorites Method | BreakLink Method | CanCheckIn Method | ChangeFileAccess Method | ChangeLink Method | CheckIn Method | Close Method | DeleteNumberFormat Method | EndReview Method | ExclusiveAccess Method | FollowHyperlink Method | ForwardMailer Method | HighlightChangesOptions Method | LinkInfo Method | LinkSources Method | MergeWorkbook Method | NewWindow Method | OpenLinks Method | PivotCaches Method | Post Method | PrintOut Method | PrintPreview Method | Protect Method | ProtectSharing Method | PurgeChangeHistoryNow Method | RecheckSmartTags Method | RefreshAll Method | RejectAllChanges Method | ReloadAs Method | RemoveUser Method | Reply Method | ReplyAll Method | ReplyWithChanges Method | ResetColors Method | Route Method | RunAutoMacros Method | Save Method | SaveAs Method | SaveAsXMLData Method | SaveCopyAs Method | SendFaxOverInternet Method | SendForReview Method | SendMail Method | SendMailer Method | SetLinkOnData Method | SetPasswordEncryptionOptions Method | Unprotect Method | UnprotectSharing Method | UpdateFromFile Method | UpdateLink Method | WebPagePreview Method | XmlImport Method | XmlImportXml Method

Events | Activate Event | AddinInstall Event | AddinUninstall Event | AfterXmlExport Event | AfterXmlImport Event | BeforeClose Event | BeforePrint Event | BeforeSave Event | BeforeXmlExport Event | BeforeXmlImport Event | Deactivate Event | NewSheet Event | Open Event | PivotTableCloseConnection Event | PivotTableOpenConnection Event | SheetActivate Event | SheetBeforeDoubleClick Event | SheetBeforeRightClick Event | SheetCalculate Event | SheetChange Event | SheetDeactivate Event | SheetFollowHyperlink Event | SheetPivotTableUpdate Event | SheetSelectionChange Event | Sync Event | WindowActivate Event | WindowDeactivate Event | WindowResize Event

Parent Objects | Application Object | Workbooks Collection

Child Objects | Chart Object | CustomViews Object | Mailer Object | Names Object | PublishObjects Object | RoutingSlip Object | Sheets Object | SmartTagOptions Object | Styles Object | WebOptions Object | Windows Object | XmlMaps Object | XmlNamespaces Object

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