1 | #include <Debug.au3> |
---|
2 | |
---|
3 | _DebugSetup("Debug Out", False, 1) |
---|
4 | _DebugOut("Debug start") |
---|
5 | |
---|
6 | Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") |
---|
7 | |
---|
8 | ;----------------------------------------------------------------------- |
---|
9 | ; Setup Excel environment |
---|
10 | ;----------------------------------------------------------------------- |
---|
11 | $oExcel = ObjCreate("Excel.Application") |
---|
12 | $oExcel.Visible = True |
---|
13 | $oExcel.SheetsInNewWorkbook = 1 |
---|
14 | |
---|
15 | ;----------------------------------------------------------------------- |
---|
16 | ; Create workbook and fill with sheets |
---|
17 | ;----------------------------------------------------------------------- |
---|
18 | $oWB = $oExcel.workbooks.add |
---|
19 | for $i = 1 to 5 |
---|
20 | $oWB.Sheets.Add |
---|
21 | _DebugOut("Now " & $oWB.Worksheets.Count & " sheets in workbook") |
---|
22 | Sleep(1000) |
---|
23 | Next |
---|
24 | |
---|
25 | ;----------------------------------------------------------------------- |
---|
26 | ; Delete all sheets using FOR .. IN .. NEXT loop |
---|
27 | ; Will crash deleting last sheets but that is not the issue here and I decided to leave it in |
---|
28 | ;----------------------------------------------------------------------- |
---|
29 | For $sheet In $oWB.Worksheets |
---|
30 | $sheet.Delete |
---|
31 | _DebugOut("Now " & $oWB.Worksheets.Count & " sheets in workbook") |
---|
32 | Sleep(1000) |
---|
33 | Next |
---|
34 | |
---|
35 | Exit |
---|
36 | |
---|
37 | ;----------------------------------------------------------------------- |
---|
38 | ; Error Handler |
---|
39 | ;----------------------------------------------------------------------- |
---|
40 | Func MyErrFunc($oMyError) |
---|
41 | Local $HexNumber |
---|
42 | Local $strMsg |
---|
43 | |
---|
44 | $HexNumber = Hex($oMyError.Number, 8) |
---|
45 | $strMsg = "Error Number: " & $HexNumber & @CRLF |
---|
46 | $strMsg &= "WinDescription: " & $oMyError.WinDescription & @CRLF |
---|
47 | $strMsg &= "Script Line: " & $oMyError.ScriptLine & @CRLF |
---|
48 | MsgBox(0, "ERROR", $strMsg) |
---|
49 | SetError(1) |
---|
50 | |
---|
51 | Endfunc |
---|