Workbook Object

Description

Represents a Microsoft Excel workbook.

Accessors

The Workbook object is a member of the Workbooks collection. The Workbooks collection contains all the Workbook objects currently open in Microsoft Excel. Use the Open method to open a file. Use the Add method to create a new empty workbook and add it to the collection.

To access a single member of the collection, use the Workbooks method with the index number or name of the workbook as an argument.

The index number represents the order in which the workbooks were opened or created. Workbooks(1) is the first workbook created; Workbooks(Workbooks.Count) is the last. Activating a workbook does not change its index number. All workbooks are included in the index count, even if they are hidden. The following example activates workbook one.


Workbooks(1).Activate

The Name property returns the workbook name. You cannot set the name using this property. Use the SaveAs method to save the workbook under a different name if you need to change the name. The following example activates the worksheet named "Sheet1" in the workbook named COGS.XLS (the workbook must already be open in Microsoft Excel).


Workbooks("cogs.xls").Worksheets("sheet1").Activate

Using ActiveWorkbook

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


ActiveWorkbook.Author = "Jean Selva"

Using ThisWorkbook

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 will not return the active workbook. In this case, the active workbook is the workbook calling the add-in, while the ThisWorkbook property returns the add-in workbook.

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

Properties

ActiveChart Property, ActiveSheet Property, Application Property, Author Property, BuiltinDocumentProperties Property, Colors Property, Comments Property, Container Property, CreateBackup Property, Creator Property, CustomDocumentProperties Property, Date1904 Property, DisplayDrawingObjects Property, FileFormat Property, FullName Property, HasMailer Property, HasPassword Property, HasRoutingSlip Property, Keywords Property, Mailer Property, MultiUserEditing Property, Name Property, OnSave Property, OnSheetActivate Property, OnSheetDeactivate Property, Parent Property, Path Property, PrecisionAsDisplayed Property, ProtectStructure Property, ProtectWindows Property, ReadOnly Property, ReadOnlyRecommended Property, RevisionNumber Property, Routed Property, RoutingSlip Property, Saved Property, SaveLinkValues Property, ShowConflictHistory Property, Subject Property, Title Property, UpdateRemoteReferences Property, UserStatus Property, WriteReserved Property, WriteReservedBy Property.

Methods

Activate Method, ChangeFileAccess Method, ChangeLink Method, Charts Method, Close Method, DeleteNumberFormat Method, DialogSheets Method, EditionOptions Method, Excel4IntlMacroSheets Method, Excel4MacroSheets Method, ExclusiveAccess Method, ForwardMailer Method, LinkInfo Method, LinkSources Method, Modules Method, Names Method, NewWindow Method, OpenLinks Method, Post Method, PrintOut Method, PrintPreview Method, Protect Method, Reply Method, ReplyAll Method, Route Method, RunAutoMacros Method, Save Method, SaveAs Method, SaveCopyAs Method, SendMail Method, SendMailer Method, SetLinkOnData Method, Sheets Method, Styles Method, Unprotect Method, UpdateFromFile Method, UpdateLink Method, Windows Method, Worksheets Method.