don00 Posted March 9, 2021 Share Posted March 9, 2021 Hello; I would appreciate your assistance, now after i chose the folder path, the array display will show all the excel files inside this folder, lets say there are 4 excel files inside this chosen folder, how i could pick and call each excel file inside this array to do specific tasks later on it? #include <Excel.au3> #include <MsgBoxConstants.au3> #include <File.au3> #include <Array.au3> MAIN() Func MAIN() Local $sFolderPath = FileSelectFolder("Please choose your Folder", "") Local $aFileList = _FileListToArray($sFolderPath, "*.xls*") _ArrayDisplay($aFileList) Link to comment Share on other sites More sharing options...
Marc Posted March 9, 2021 Share Posted March 9, 2021 #include <Excel.au3> #include <MsgBoxConstants.au3> #include <File.au3> #include <Array.au3> MAIN() Func MAIN() Local $sFolderPath = FileSelectFolder("Please choose your Folder", "") Local $aFileList = _FileListToArray($sFolderPath, "*.xls*") for $i = 1 to UBound($aFileList)-1 ConsoleWrite($sFolderPath & "\" & $aFileList[$i] & @CRLF) ShellExecute($sFolderPath & "\" & $aFileList[$i]) Sleep(500) Next EndFunc for example, this way the "sleep(500)" is needed at least on my PC here, otherwise excel would not open all files. Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL) Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted March 9, 2021 Share Posted March 9, 2021 (edited) @don00 In this case, you have a 1-dimension array, which is a set of elements you can access specifying which element do you need to. Array elements starts from 0 to the upper bound (-1) of the array, which you can obtain using UBound() function. So, to pick up each Excel file and use it later on in your script, you should use a For...Next loop: For $i = 1 To $aFileList[0] Step 1 ; Process Excel file here, i.e. with _Excel* functions $oWorkbook = _Excel_BookOpen($aFileList[$i]) Next In this specific case, the UBound() function is not needed since you already have the UBound() stored in the first element of the array. Hope it makes the things clearer. EDIT: @Marc If you use UBound() - 1 you are not picking the last element in your array, which, in this case, is a filename Sorry! I made confusion with VBA UBound(), which returns the upper bound of the array starting from 0, instead of AutoIt UBound, which returns the number of elements (in this case) Cheers Edited March 9, 2021 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
don00 Posted March 9, 2021 Author Share Posted March 9, 2021 thank you for your kind reply, i just have an error. i have attached the screenshots for both, the error i got from the FOR loop, also the file list display array just to show how many files inside. to be able to call them correctly. these files are the once i need to call one by one to proceed specific tasks on them. Link to comment Share on other sites More sharing options...
Marc Posted March 9, 2021 Share Posted March 9, 2021 (edited) @FrancescoDiMuro sorry, but I have to disagree. Having two xls-Files in my folder, Ubound() returns three. And both files get opened @don00 the help file says: _Excel_BookOpen ( $oExcel, $sFilePath [, $bReadOnly = False [, $bVisible = True [, $sPassword = Default [, $sWritePassword = Default [, $bUpdateLinks = Default]]]]] ) So you'd need to use something like (just copied from the help file) ; Create application object Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpen Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ; Open an existing workbook and return its object identifier. Local $sWorkbook = @ScriptDir & "\Extras\_Excel1.xls" Local $oWorkbook = _Excel_BookOpen($oExcel, $sWorkbook) Edited March 9, 2021 by Marc FrancescoDiMuro 1 Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL) Link to comment Share on other sites More sharing options...
don00 Posted March 11, 2021 Author Share Posted March 11, 2021 Thank you for your kind support. Link to comment Share on other sites More sharing options...
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