Jump to content
Sign in to follow this  
lolipop

Excel doesn't close after command

Recommended Posts

lolipop

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.

#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

Share this post


Link to post
Share on other sites
nitekram

I do not have excel on this computer, but can you put a msgbox after the close to find out what the @error might be?

If @error Then MsgBox('','ERROR',@error)
Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites
lolipop

Thanks nitekram, Added the msgbox but there's no error message at all. It seems to exceute the proceed along.

Share this post


Link to post
Share on other sites
nitekram

Does it created the next GUI ie. Create_Form3(), if not - exit your loop first and then at the bottom call the function:

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
Create_Form3()
EndFunc ;==>Create_Form1

I might be off base here, as your stating in your first post that Excel is not closing - so everything else is going as planned?

EDIT

Try this too, maybe you are not seeing the prompt to save???

_ExcelBookClose($oExcel, 1, 1)

might be getting tired, sorry -change it to a 1 to see the prompt

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites
lolipop

yes it does create the next gui form3. As I mention, it seems to process the _excelbookclose successfully but when I open the task manager and look, the Excel.exe process is still there.

Share this post


Link to post
Share on other sites
nitekram

Oh, I misunderstood everything. Without excel I am not going to be able to tell what is going on, but you could kill the process within your script? I know @water will be able to answer, but he is not online


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites
nitekram

Just to make sure, can you verify before the script runs that there are no process for excel opened? and put a msgbox, right before you close to check how many are running at that time

edit - stupid keyboard does not know how to type

EDIT - he (@water) will also need to know which version of excel you are running

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites
4gotn1

#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)
If ProcessExists("excel.exe") Then ProcessClose("excel.exe")

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

Something like this should kill excel.exe when you hit "Button 2". You'll have to elaborate on the temp.xls however.

-Cheers

Edited by 4gotn1

Share this post


Link to post
Share on other sites
nitekram

I might have found it - you open an object for excel in your code? with this function ExcelFindLastRow()

edit - easy enough to test on your end - just comment out the call to that function and see if it resolves?

edit - sorry, and just hard code last row?

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites
nitekram

#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)
If ProcessExists("excel.exe") Then ProcessClose("excel.exe")

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

Something like this should kill excel.exe when you hit "Button 2". You'll have to elaborate on the temp.xls however.

-Cheers

I think this line If ProcessExists("excel.exe") Then ProcessClose("excel.exe") needs to be at the bottom before OP is exiting out of the loop, if OP is going to go that route,

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites
lolipop

I might have found it - you open an object for excel in your code? with this function ExcelFindLastRow()

edit - easy enough to test on your end - just comment out the call to that function and see if it resolves?

edit - sorry, and just hard code last row?

Yes, I did open an object with function ExcelFindLastRow(). It was from some example I found in the forum and I modify it for use. This there a way to close that object properly? I have tried to include the _ExcelBookClose into the function ExcelFindLastRow(), but it doesn't seems to work.

The number of row for the excel spreadsheet is not the same everytime I open it(By design) has I can't hardcode the last row. I need some ways to always calculate the last row before I can proceed with the rest of the program. Perhaps you have other advise for me?

Basically I'm writing a basic login system with the excel spreadsheet as the database containing users particulars. Therefore the entry in the excel spreadsheet is always changing.

Btw the excel version is Excel 2010

Edited by lolipop

Share this post


Link to post
Share on other sites
lolipop

Something like this should kill excel.exe when you hit "Button 2". You'll have to elaborate on the temp.xls however.

-Cheers

Thanks 4gotn1 but I really don't wish to go thru the ProcessClose command way becos when I close it this way excel doesn't seems to close properly. When I open the excel spreadsheet manually, excel will always prompt me that the previous session didn't close properly and asking me if I wanted to do document recovery for it.

Share this post


Link to post
Share on other sites
nitekram

Look in the help file for _ExcelReadSheetToArray(), you should be able to use this?

EDIT removed code, as I would have to have excel sheet to test, plus have excel installed

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites
lolipop

After searching thru the forum countless time. Finally manage to solve the problem. It seems to be a bug of Excel 2010. More info @

The fix is simply. Just add $oExcel = 0 after _ExcelBookClose and Excel should release the obj the close. Weird that the bug still exist cos Water seems to mention that it was fix in one of the beta some time back.

Thanks nitekram for the help. :)

Share this post


Link to post
Share on other sites
nitekram

Watch for an updated version of his UDF, as @water is in the process of creating an Alpha version of it. AND it is much faster reading the files.


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites
water

After searching thru the forum countless time. Finally manage to solve the problem. It seems to be a bug of Excel 2010. More info @

The fix is simply. Just add $oExcel = 0 after _ExcelBookClose and Excel should release the obj the close. Weird that the bug still exist cos Water seems to mention that it was fix in one of the beta some time back.

The problem I had was caused by me. If you run a 64 bit OS and the 32 bit version of Office you have to compile your AutoIt scripts fro 32 bit.

So it's not a bug in AutoIt but a user problem.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

Watch for an updated version of his UDF, as @water is in the process of creating an Alpha version of it. AND it is much faster reading the files.

I hope to release a new alpha quite soon.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
lolipop

The problem I had was caused by me. If you run a 64 bit OS and the 32 bit version of Office you have to compile your AutoIt scripts fro 32 bit.

So it's not a bug in AutoIt but a user problem.

Don't worry water, I'm not saying it's autoit bug. I think I read somewhere that it's due to Excel not releasing the obj properly. Fyi, I'm using office 2010, running 32bit windows 7 and compiling in 32bit but I still face the same problem.

Can't wait for the new release of Excel UDF. Nice job. :thumbsup:

Share this post


Link to post
Share on other sites
water

Not closing the Excel application is caused by this line in your code:

$oExcel = _ExcelBookOpen($sFilePath,0)
After the function call $oExcel contains a reference to the Excel application. As long as this reference "points" to Excel the application is still running.

So you need to reset all global variables ($oExcel, ) to 0 to end Excel.

In the new UDF function _Excel_Close does this automatically.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×