Akshay07 Posted December 29, 2009 Posted December 29, 2009 (edited) Hi, I have a problem with a piece of code. What I want to achieve is the following 1/ Open an excel file 2/ Save it with another name. It works fine til that point 3/ Closing it --> This does not work Here is the piece of script $oExcel = _ExcelBookSaveAs($oExcelTemplate, $sPath & $sName & ".xls") ; this works _ExcelBookClose($oExcel, 0, 0) ; Excel is not closed I also tried Here is the piece of script $oExcel = _ExcelBookSaveAs($oExcelTemplate, $sPath & $sName & ".xls") ; this works _ExcelBookClose($oExcel, 0, 1) ; Excel is not closed to enable Excel message alert but I don't get any alert. PS: I know I could kill the process, but I would like to understand why ExcelBookClose does not work in the script Edited December 29, 2009 by Akshay07
PsaltyDS Posted December 29, 2009 Posted December 29, 2009 You are destroying your $oExcel object reference or using the wrong variable when you save the return value from _ExcelBookSaveAs() over it: $iRET = _ExcelBookSaveAs($oExcelTemplate, $sPath & $sName & ".xls") If $iRET Then _ExcelBookClose($oExcelTemplate, 0, 1) Else MsgBox(16, "Error", "Failed to save changes.") EndIf Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Akshay07 Posted December 29, 2009 Author Posted December 29, 2009 (edited) You are destroying your $oExcel object reference or using the wrong variable when you save the return value from _ExcelBookSaveAs() over it: $iRET = _ExcelBookSaveAs($oExcelTemplate, $sPath & $sName & ".xls") If $iRET Then _ExcelBookClose($oExcelTemplate, 0, 1) Else MsgBox(16, "Error", "Failed to save changes.") EndIf Thank you for your test code. I was very careful to not reuse an existing object, but well, as you know, one can always miss something. So I did implement your piece of script and I did not get any error message after the $iRET = _ExcelBookSaveAs($oExcelTemplate, $sPath & $sName & ".xls") Therefore, I still have a problem. Edited December 29, 2009 by Akshay07
microera Posted January 11, 2010 Posted January 11, 2010 yes! I test with AutoIt v3.3.2.0 and on one computer _ExcelBookClose($oExcel) work ok but on another NOT! Where is problem?
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