Hi,
Can anyone advise me why my excel process doesn't close after clicking button 2 even after I state in the code to close the excel process. Btw, need to create a temp.xls file in the script directory. Thanks.
Can anyone advise me why my excel process doesn't close after clicking button 2 even after I state in the code to close the excel process. Btw, need to create a temp.xls file in the script directory. Thanks.
[ autoit ]
#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <Date.au3> #include <Excel.au3> #include <ListViewConstants.au3> #include <Array.au3> #include <GuiListView.au3> Global $CurrentTime = @HOUR&":"&@MIN;&":"&@SEC Global $CurrentDate = @YEAR&"/"&@MON&"/"&@MDAY Global $ExcelSignOutArray[3] = [$CurrentDate, $CurrentTime, "Sign-Out"] Global $ExcelSignOutArrayWRemark[4] = [$CurrentDate, $CurrentTime, "Sign-Out", "System Auto Sign-Out"] Global $sFilePath = @ScriptDir & "\temp.xls" Create_Form1() Func Create_Form1() $Form1 = GUICreate("XXX", 485, 531, -1, -1) GUISetBkColor(0xFFFFFF) $Form1_Graphic1 = GUICtrlCreateGraphic(0, 0, 490, 161) GUICtrlSetBkColor(-1, 0x9BBB58) $Form1_Label1 = GUICtrlCreateLabel("XXX", 40, 40, 218, 52) GUICtrlSetFont(-1, 27, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFBF0) GUICtrlSetBkColor(-1, 0x9BBB58) $Form1_Label2 = GUICtrlCreateLabel("XXX", 40, 72, 268, 52) GUICtrlSetFont(-1, 27, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFBF0) GUICtrlSetBkColor(-1, 0x9BBB58) $Form1_Label3 = GUICtrlCreateLabel("XXX", 98, 200, 289, 33) GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif") $Form1_Label4 = GUICtrlCreateLabel("XXX", 64, 296, 151, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Form1_Label5 = GUICtrlCreateLabel("XXX", 64, 320, 154, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Form1_Label6 = GUICtrlCreateLabel("XXX", 64, 416, 160, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Form1_Label7 = GUICtrlCreateLabel("XXX", 64, 440, 106, 20) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") $Form1_Button1 = GUICtrlCreateButton("Button1", 236, 292, 201, 45, $BS_BITMAP) $Form1_Button2 = GUICtrlCreateButton("Button2", 236, 416, 201, 45, $BS_BITMAP) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE $Form1_Result1 = MsgBox(52,"", "Are you sure you want to exit?") If $Form1_Result1 = 6 Then Exit Case $msg = $Form1_Button1 GUIDelete($Form1) Create_Form2() ExitLoop Case $msg = $Form1_Button2 GUIDelete($Form1) Global $oExcel = _ExcelBookOpen($sFilePath,0) ExcelFindLastRow() Global $ConcatVal = "Sign-In" Global $aFound = _ExcelFindInRange($oExcel, $ConcatVal, "L1:L"&$iLastRow) ;Found the total number of row with $ConcatVal keyword Global $TotalSignIn = $aFound[0][0] $i = 1 While $i <= $TotalSignIn Global $SelectedRow = $aFound[$i][3] Global $AutoSignOutDateDiffData = _ExcelReadArray($oExcel, $SelectedRow, 1, 13, 0);The individual column data respective to $TotalSignIn $ConvertYear = StringMid ($AutoSignOutDateDiffData[7], 1, 4) $ConvertMonth = StringMid ($AutoSignOutDateDiffData[7], 5, 2) $ConvertDate = StringMid ($AutoSignOutDateDiffData[7], 7, 2) $CombineDate = $ConvertYear&"/"&$ConvertMonth&"/"&$ConvertDate $AutoSignOutDateDiff = _DateDiff("D", $CombineDate, _NowCalcDate()) If $AutoSignOutDateDiff >= 1 Then _ExcelWriteArray($oExcel, ($aFound[$i][3]), 10, $ExcelSignOutArrayWRemark, 0) EndIf $i = $i + 1 WEnd _ExcelBookClose($oExcel,1) Create_Form3() ExitLoop EndSelect WEnd EndFunc Func Create_Form3() $Form3 = GUICreate("X", 485, 531, -1, -1) GUISetBkColor(0xFFFFFF) $Form3_Graphic1 = GUICtrlCreateGraphic(0, 0, 490, 161) GUICtrlSetBkColor(-1, 0x9BBB58) $Form3_Label1 = GUICtrlCreateLabel("X", 40, 40, 218, 52) GUICtrlSetFont(-1, 27, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFBF0) GUICtrlSetBkColor(-1, 0x9BBB58) $Form3_Label2 = GUICtrlCreateLabel("X", 40, 72, 268, 52) GUICtrlSetFont(-1, 27, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFFFBF0) GUICtrlSetBkColor(-1, 0x9BBB58) Global $Form3_ListView1 = GUICtrlCreateListView("1|2|3|4|5", 0, 161, 485, 250, BitOR($GUI_SS_DEFAULT_LISTVIEW,$LVS_SINGLESEL,$LVS_NOSORTHEADER), $LVS_EX_FULLROWSELECT) GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 35) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 130) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 90) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 3, 130) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 4, 100) $Form3_Button4 = GUICtrlCreateButton("Button4", 145, 420, 201, 45, $BS_BITMAP) $Form3_Button3 = GUICtrlCreateButton("Button3", 8, 496, 73, 30, $BS_BITMAP) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE $Form3__Result1 = MsgBox(52,"", "Are you sure you want to exit?") If $Form3__Result1 = 6 Then Exit Case $Form3_Button4 GUIDelete($Form3) Create_Form1() ExitLoop Case $Form3_Button3 GUIDelete($Form3) Create_Form1() ExitLoop EndSwitch WEnd EndFunc Func ExcelFindLastRow() $oExcel1 = ObjGet($sFilePath, "Excel.Application") $oSheet = $oExcel1.ActiveSheet Global $iLastRow = $oSheet.Cells.Find('*', $oSheet.Cells(1, 1), Default, Default, 1, 2).Row EndFunc Func _ExcelFindInRange($oExcel, $sFindWhat, $sRangeOrRowStart, $iColStart = 1, $iRowEnd = 1, $iColEnd = 1, $iDataType = 0, $iWholeOrPart = 2, $fMatchCase = False, $fMatchFormat = "") Local $iCount, $sA1, $sR1C1, $sFound, $Temp1, $Temp2, $sFirst If NOT IsObj($oExcel) Then Return SetError(1, 0, 0) If $iDataType <> 0 Then If $iDataType <> -4163 Or $iDataType <> -4123 Or $iDataType <> -4144 Then Return SetError(4, 0, 0) EndIf EndIf If $iWholeOrPart < 1 Or $iWholeOrPart > 2 Then Return SetError(5, 0, 0) If NOT StringRegExp($sRangeOrRowStart, "[A-Z,a-z]", 0) Then If $sRangeOrRowStart < 1 Then Return SetError(2, 0, 0) If $iColStart < 1 Then Return SetError(2, 1, 0) If $iRowEnd < $sRangeOrRowStart Then Return SetError(3, 0, 0) If $iColEnd < $iColStart Then Return SetError(3, 1, 0) $oExcel.Range($oExcel.Cells($sRangeOrRowStart, $iColStart), $oExcel.Cells($iRowEnd, $iColEnd)).Select Else $oExcel.Range($sRangeOrRowStart).Select EndIf If $iDataType = 0 Then If $fMatchFormat = "" Then $oFound = $oExcel.Selection.Find($sFindWhat, $oExcel.ActiveCell, Default, $iWholeOrPart, Default, Default, $fMatchCase, Default) Else $oFound = $oExcel.Selection.Find($sFindWhat, $oExcel.ActiveCell, Default, $iWholeOrPart, Default, Default, $fMatchCase, Default, $fMatchFormat) EndIf Else If $fMatchFormat = "" Then $oFound = $oExcel.Selection.Find($sFindWhat, $oExcel.ActiveCell, $iDataType, $iWholeOrPart, Default, Default, $fMatchCase, Default) Else $oFound = $oExcel.Selection.Find($sFindWhat, $oExcel.ActiveCell, $iDataType, $iWholeOrPart, Default, Default, $fMatchCase, Default, $fMatchFormat) EndIf EndIf If IsObj($oFound) Then $oFound.Activate Else Local $aFound[1][1] $aFound[0][0] = 0 Return $aFound EndIf While 1 If $iCount > 0 And $iCount < 2 Then $sFirst = $sA1 $Temp1 = $oExcel.ActiveCell.Address $Temp2 = $oExcel.ActiveCell.Address(True, True, $xlR1C1) If $Temp1 = $sFirst Then ExitLoop If $iCount > 0 Then $sA1 = $sA1 & "*" & $Temp1 $sR1C1 = $sR1C1 & "*" & $Temp2 Else $sA1 = $Temp1 $sR1C1 = $Temp2 EndIf $iCount += 1 $oExcel.Selection.FindNext($oExcel.ActiveCell).Activate WEnd Local $aFound[$iCount + 1][4] $sA1 = StringReplace($sA1, "$", "") Local $aA1 = StringSplit($sA1, "*") Local $aR1C1 = StringSplit($sR1C1, "*") $aFound[0][0] = $iCount For $xx = 1 To $iCount $aFound[$xx][0] = $aA1[$xx] $aFound[$xx][1] = $aR1C1[$xx] $Temp1 = StringRegExp($aR1C1[$xx], "[RZ]([^CS]*)[CS](.*)",3) $aFound[$xx][2] = Number($Temp1[1]) $aFound[$xx][3] = Number($Temp1[0]) Next Return $aFound _ExcelBookClose($oExcel, 1, 0) EndFunc