Close Method

The Close method closes the workbook. Its syntax is:

WorkbookObject.Close(SaveChanges, FileName, RouteWorkbook)

Note that the Close method of the Workbook object has three parameters, unlike the Close method of the Workbooks object, which has none.

The optional SaveChanges parameter is used to save changes to the workbook before closing. In particular, if there are no changes to the workbook, the argument is ignored. It is also ignored if the workbook appears in other open windows. On the other hand, if there are changes to the workbook and it does not appear in any other open windows, the argument takes effect.

In this case, if SaveChanges is True, the changes are saved. If there is not yet a filename associated with the workbook (that is, if it has not been previously saved), then the name given in FileName is used. If FileName is also omitted, Excel will prompt the user for a filename. If SaveChanges is False, changes are not saved. Finally, if the SaveChanges argument is omitted, Excel will display a dialog box asking whether the changes should be saved. In short, this method behaves as you would hope.

The optional RouteWorkbook refers to routing issues; we refer the interested reader to the Excel VBA help file for more information.

It is important to note that the Close method checks the Saved property of the workbook to determine whether or not to prompt the user to save changes. If we set the Saved property to True, then the Close method will simply close the workbook with no warning and without saving any unsaved changes.

0 0

Post a comment