Close A Workbook

You can close a particular workbook from your macro using the Close method and including a reference to the Workbook object that contains the workbook you want to close. The Workbooks collection contains all of the currently open workbooks as individual workbook objects. The Workbooks collection adds the Workbook objects sequentially in the order you opened them. You reference a workbook with an index value, the name of the workbook, the ActiveWorkbook property, or the ThisWorkbook property.

When you use the ActiveWorkbook or ThisWorkbook property with the Close method the current workbook running the macro closes. If you have code after the Close statement, Excel may ignore it.

There are three different optional parameters that you can use with the Close method: SaveChanges, Filename, and RouteWorkbook.

You can use the SaveChanges parameter to save changes to a workbook as it closes. If you specify a parameter value of True, the workbook saves as it closes;with a value of False, however, the workbook closes without Excel saving it, and you lose any changes you made to the workbook.

You can specify a filename and path if you utilize the FileName parameter to save the workbook. Keep in mind, if you specify a value of False for the SaveChanges parameter, Excel ignores the FileName parameter because the file is never saved. Excel only saves the workbook if you have made changes to it.

If you set up the workbook to route, you can use the RouteWorkbook parameter to route the workbook to the next recipient on the routing list. Specify a value of True to route the workbook or a value of False if you do not want to have the workbook sent to the next recipient.

CLOSE A WORKBOOK

CLOSE A WORKBOOK

—n Create a new subroutine.

-0 Type Workbooks ("workbook.xls").Close, replacing workbook.xls with the name of the workbook to close.

—n Create a new subroutine.

-0 Type Workbooks ("workbook.xls").Close, replacing workbook.xls with the name of the workbook to close.

0 0

Post a comment