Close Method

Applies To

Window object, Workbook object, Workbooks collection object.

Description

Closes the object. The Workbooks collection uses Syntax 1. Window and Workbook objects use Syntax 2.

Syntax 1

expression.Close

Syntax 2

expression.Close(SaveChanges, FileName, RouteWorkbook)

expression Required. An expression that returns an object in the Applies To list.

SaveChanges Optional Variant. If there are no changes to the workbook, this argument is ignored. If there are changes to the workbook and the workbook appears in other open windows, this argument is ignored. If there are changes to the workbook but the workbook doesn't appear in any other open windows, this argument specifies whether changes should be saved, as shown in the following table.

Value

Action

True

Saves the changes to the workbook. If there is not yet a file name associated with the workbook, then FileName is used. If FileName is omitted, the user is asked to supply a file name.

False

Does not save the changes to this file.

Omitted

Displays a dialog box asking the user whether or not to save changes.


FileName Optional Variant. Save changes under this file name.

RouteWorkbook Optional Variant. If the workbook doesn't need to be routed to the next recipient (if it has no routing slip or has already been routed), this argument is ignored. Otherwise, Microsoft Excel routes the workbook as shown in the following table.

Value

Meaning

True

Sends the workbook to the next recipient.

False

Doesn't send the workbook.

Omitted

Displays a dialog box asking the user whether the workbook should be sent.


Remarks

Closing a workbook from Visual Basic doesn't run any Auto_Close macros in the workbook. Use the RunAutoMacros method to run the auto close macros.

Example

This example closes Book1.xls and discards any changes that have been made to it.

Workbooks("BOOK1.XLS").Close SaveChanges:=False
This example closes all open workbooks. If there are changes in any open workbook, Microsoft Excel displays the appropriate prompts and dialog boxes for saving changes.

Workbooks.Close