Closes the specified workbook
#include <Excel.au3>
_Excel_BookClose ( $oWorkbook [, $bSave = True] )
$oWorkbook | Workbook object |
$bSave | [optional] If True the workbook will be saved before closing (default = True) |
Success: | 1. |
Failure: | 0 and sets @error. |
@error: | 1 - $oWorkbook is not an object or not a workbook object 2 - Error occurred when saving the workbook. @extended is set to the COM error code returned by the Save method 3 - Error occurred when closing the workbook. @extended is set to the COM error code returned by the Close method |
_Excel_BookAttach, _Excel_BookNew, _Excel_BookOpen, _Excel_BookOpenText
#include <Excel.au3>
#include <MsgBoxConstants.au3>
; Create application object
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Create a new workbook, write some data and close it without saving
; Create the new workbook
Local $oWorkbook = _Excel_BookNew($oExcel)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Error creating new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
; Write something into cell A1
_Excel_RangeWrite($oWorkbook, Default, "Test", "A1")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Error writing to cell 'A1'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox(64, "Excel UDF: _Excel_BookClose Example 1", "Click OK to close the workbook without saving.")
; Close the workbook without saving
_Excel_BookClose($oWorkbook, False)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Error saving workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookClose Example 1", "Workbook has been successfully closed.")