Skip to main content

Workbooks object

Table of contents
  1. Remarks
  2. Examples

A collection of all the Workbook objects that are currently open in the Microsoft Excel application.

Remarks

For more information about using a single Workbook object, see the Workbook object.

Examples

Use the Workbooks property of the Application object to return the Workbooks collection.

The following example closes all open workbooks.

Workbooks.Close

Use the Add method to create a new, empty workbook and add it to the collection.

The following example adds a new, empty workbook to Microsoft Excel.

Workbooks.Add

Use the Open method to open a file. This creates a new workbook for the opened file.

The following example opens the file Products.xlsx as a read-only workbook.

Workbooks.Open FileName:="Products.xlsx", ReadOnly:=True

This example activates the workbook Book1.xls.

Workbooks("Book1").Activate

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

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

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>