TDS Posted October 2, 2024 Posted October 2, 2024 Hey folks Brand new to AutoIT, I feel like I'm making alright progress for my first day, I'm not really a programmer here Here's what i'm running into I have a loop running that opens a program and then cuts and pastes the date into excel. then keeps looping through a bunch of files, ive cobbled together the below The issue here is that the loop executes once, and then quits with error: $oWorkbook.Sheets(3).Activate $oWorkbook^ ERROR I'm also noticing that the _Excel_SheetAdd($oWorkbook,3,1) command isn't executing either, which leads me to think the $oWorkbook variable is broken, but the first time through the loop it activates sheet 3 properly, so it can't be that, I'm a bit lost since I did have this loop working properly earlier with seemingly the same code. Thanks for (any) help expandcollapse popup#include <Date.au3> #include <Excel.au3> $iTodaysDate = _NowCalc() $search = FileFindFirstFile("C:\Users\TestUser\Downloads\temp\*.Qcc") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop $FDate = FileGetTime($file, 0) $FileDate = $FDate[0] & "/" & $FDate[1] & "/" & $FDate[2] & " " & $FDate[3] & ":" & $FDate[4] & ":" & $FDate[5] If _DateDiff('D', $FileDate, $iTodaysDate) < 3 Then FileCopy($file, "C:\Users\TestUser\Downloads\temp\CurrentDay\" & $file, 1) EndIf WEnd ; Close the search handle FileClose($search) ; that copies the files modified to the working directory, now we need to loop through them Global $oExcel = _Excel_Open() Global $oWorkbook = _Excel_BookNew($oExcel,5) $ExcelSaveFile = "C:\Users\TestUser\Downloads\temp\CurrentDay\_Output_.xlsx" Local $sWorkbook = $ExcelSaveFile _Excel_BookSaveAs($oWorkbook, $sWorkbook, 51, True) ; now bring the qcc files into the excel sheet winclose("Dataset SPC (3.4.162)") $outsheet = 3 ;================================================================ ;Loop Prep Start $search2 = FileFindFirstFile("C:\Users\TestUser\Downloads\temp\CurrentDay\*.Qcc") ; Check if the search was successful If $search2 = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search2) If @error Then ExitLoop ;================================================================ Run(@comspec & ' /c start ' & $file) WinWaitActive("Dataset SPC - License Status") Send("{RIGHT}") Send("{ENTER}") WinWaitActive("Dataset SPC") Send("{ENTER}") WinWaitActive("Dataset SPC (3.4.162)") winsetstate("Dataset SPC (3.4.162)","",@SW_MAXIMIZE) sleep(500) mousemove(-1873,160,0) mousedown($MOUSE_CLICK_LEFT) sleep(200) mouseup($MOUSE_CLICK_LEFT) mousemove(-1519,103,0) mousedown($MOUSE_CLICK_LEFT) sleep(200) mouseup($MOUSE_CLICK_LEFT) sleep(500) send("^c") ; copy contents to clipboard sleep(400) winclose("Dataset") sleep(200) winactivate("Excel") $oWorkbook.Sheets(3).Activate sleep(50) $oExcel.Application.ActiveSheet.Range("A3").Select sleep(100) send("^v") sleep(100) $oExcel.Application.ActiveSheet.Range("A1").Select sleep(50) $title = string($file) send($title) sleep(100) _Excel_SheetAdd($oWorkbook,3,1) WEnd ; ' end of loop ;_Excel_BookSave($oWorkbook) ;$ExcelSaveFile = "C:\Users\TestUser\Downloads\temp\CurrentDay\" & $Fdate[0] & "\" & $FileDate & ".xlsx" ; put into a folder and file name for the current year date ;Local $sWorkbook = $ExcelSaveFile ;_Excel_BookSaveAs($oWorkbook, $sWorkbook, 51, True) ;msgbox(1,"",$ExcelSaveFile) winclose("_Output_.xlsx")
TDS Posted October 2, 2024 Author Posted October 2, 2024 I can't edit the above, but I found the problem it appears that , for some reason, making a string out of the file name that I opened and sending it to excel (just after the a1 select) somehow breaks everything, any thought on how I do this properly? lol $title = string($file) send($title)
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now