pete1234 Posted October 24, 2008 Share Posted October 24, 2008 This is more of a conceptual question. I have the following code: #Include <Array.au3> $BackupFiles = _ArrayCreate("C:\1.xls", "C:\2.xls", "C:\3.xls") $xlApp = ObjCreate("Excel.Application") If Not IsObj($xlApp) Then Exit With $xlApp .Visible = False .Workbooks.Open("C:\BackupMacros.xls") For $i = 0 to UBound($BackupFiles) - 1 .Run("AutoItBackup(" & chr(34) & $BackupFiles[$i] & chr(34) & ")") Next .Quit msgbox(0, "", "done") EndWith What I'm basically doing is running a macro on a bunch of different Excel files. This all works just as expected. The issue I've noticed is that if my array has only 2 elements, my code runs the macro on the first element twice. So if I change my array to only include 2 files instead of 3, and make no other changes, the macro I'm executing will run on the first file twice. If the array has 3 or more file this doesn't happen. Does anyone know what's going on? Thanks. Link to comment Share on other sites More sharing options...
Richard Robertson Posted October 24, 2008 Share Posted October 24, 2008 If I remember correctly, you shouldn't be using _ArrayCreate anyways. One of the updates says to stop using it and use the built in array initializers. Link to comment Share on other sites More sharing options...
jvanegmond Posted October 24, 2008 Share Posted October 24, 2008 (edited) I can't reproduce this problem. Also, like Richard said, don't use _ArrayCreate anymore (It's not in the latest SciTE anymore, even.) I had to comment out the Excel lines, because I don't have the 1.xls, 2.xls and 3.xls files. #include <Array.au3> Dim $BackupFiles[2] = ["C:\1.xls", "C:\2.xls"] ;$xlApp = ObjCreate("Excel.Application") ;If Not IsObj($xlApp) Then Exit ;With $xlApp ; .Visible = False ; .Workbooks.Open("C:\BackupMacros.xls") For $i = 0 to UBound($BackupFiles) - 1 ConsoleWrite("$BackupFiles[" & $i & "] = " & $BackupFiles[$i] & @CRLF) ; .Run("AutoItBackup(" & chr(34) & $BackupFiles[$i] & chr(34) & ")") Next ; .Quit ; msgbox(0, "", "done") ;EndWith $BackupFiles = _ArrayCreate("C:\1.xls", "C:\2.xls") ;$xlApp = ObjCreate("Excel.Application") ;If Not IsObj($xlApp) Then Exit ;With $xlApp ; .Visible = False ; .Workbooks.Open("C:\BackupMacros.xls") For $i = 0 to UBound($BackupFiles) - 1 ConsoleWrite("$BackupFiles[" & $i & "] = " & $BackupFiles[$i] & @CRLF) ; .Run("AutoItBackup(" & chr(34) & $BackupFiles[$i] & chr(34) & ")") Next ; .Quit ; msgbox(0, "", "done") ;EndWith Edited October 24, 2008 by Manadar github.com/jvanegmond 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