Deletes the specified sheet by object, string name or by number
#include <Excel.au3>
_Excel_SheetDelete ( $oWorkbook [, $vSheet = Default] )
$oWorkbook | A workbook object |
$vSheet | [optional] The sheet to delete, either by object, string name or number (default = keyword Default = active Worksheet) |
Success: | 1. |
Failure: | 0 and sets @error. |
@error: | 1 - $oWorkbook is not an object or not a workbook object 2 - Specified sheet does not exist. @extended is set to the COM error code 3 - Error occurred when deleting the sheet. @extended is set to the COM error code |
#include <Excel.au3>
#include <MsgBoxConstants.au3>
; Create application object and open an example workbook
Local $oExcel = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_SheetDelete Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\Extras\_Excel1.xls")
If @error Then
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_SheetDelete Example", "Error opening workbook '" & @ScriptDir & "\Extras\_Excel1.xls'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
_Excel_Close($oExcel)
Exit
EndIf
; Delete sheet number 1 of the specified workbook
_Excel_SheetDelete($oWorkbook, 1)
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_SheetDelete Example 1", "Error deleting sheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_SheetDelete Example 1", "First sheet has been deleted.")