Function Reference


_Excel_BookNew

Creates a new workbook

#include <Excel.au3>
_Excel_BookNew ( $oExcel [, $iSheets = Default] )

Parameters

$oExcel Excel application object where you want to create the new workbook
$iSheets [optional] Number of sheets to create in the new workbook (default = keyword Default = Excel default value). Maximum is 255

Return Value

Success: a new workbook object.
Failure: 0 and sets @error.
@error: 1 - $oExcel is not an object or not an application object
2 - Error setting SheetsInNewWorkbook to $iSheets. @extended is set to the COM error code
3 - Error returned by method Workbooks.Add. @extended is set to the COM error code
4 - Parameter $iSheets < 1 or > 255

Remarks

There seems to be a limit for property SheetsInNewWorkbook of 255.

Related

_Excel_BookAttach, _Excel_BookClose, _Excel_BookOpen, _Excel_BookOpenText

Example

#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 with only 2 worksheets
; *****************************************************************************
_Excel_BookNew($oExcel, 2)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookNew Example 1", "Error creating new workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookNew Example 1", "Workbook has been created successfully with only 2 worksheets.")