Workbooks Method

Applies To

Application Object.

Description

Accessor. Returns an object that represents a single open workbook (a Workbook object, Syntax 1) or a collection of all open workbooks (the Workbooks object, Syntax 2). Read-only.

Syntax 1

object.Workbooks(index)

Syntax 2

object.Workbooks

object

Optional. The Application object.

index

Required for Syntax 1. The name or number of the workbook.

Remarks

The collection returned by syntax 2 of the Workbooks method does not include open add-ins, which are a special kind of hidden workbook.

You can, however, return a single open add-in if you know the filename. For example Workbooks("OSCAR.XLA") will return the open add-in named "OSCAR.XLA" as a Workbook object.

Example

This example activates workbook BOOK1.


Workbooks("BOOK1").Activate

This example opens the workbook LARGE.XLS.


Workbooks.Open filename:="LARGE.XLS"

This example closes and saves changes to all workbooks except the one that is running the example.


For Each w In Workbooks
    If w.Name <> ThisWorkbook.Name Then
        w.Close savechanges:=True
    End If
Next w