chobo2 Posted September 23, 2016 Posted September 23, 2016 Hi I keep getting this error but the weird thing is that it only happens on one of my like 10 tests but they are all using the same code. My code is Local $oExcel = OpenExcel() Local $excelWorkBook = GetExcelWorkBook("\Files\ExcelWorkBook.xlsx", $oExcel) Local $newBidderRegWorkSheet = GetExcelWorkSheet($excelWorkBook, "Test1") CloseWorkBook($excelWorkBook) CloseExcel($oExcel) expandcollapse popupFunc OpenExcel(Const $bVisible = True, Const $bDisplayAlerts = False, Const $bScreenUpdating = True, Const $bInteractive = True, Const $bForceNew = False) Local $oExcel = _Excel_Open($bVisible, $bDisplayAlerts, $bScreenUpdating, $bInteractive, $bForceNew) If IsObj($oExcel) And @error Then Exit EndIf return $oExcel EndFunc Func GetExcelWorkBook($excelWorkbookFilePath, $oExcel) Local $fileName = @ScriptDir & $excelWorkbookFilePath If Not FileExists($fileName) Exit EndIf Local $excelWorkbook = _Excel_BookOpen($oExcel, $filename) If @error Then Exit EndIf return $excelWorkbook EndFunc Func GetExcelWorkSheet($excelWorkbook, $worksheetName) Local Const $scriptName = "ExcelHelpers.au3" $result = _Excel_RangeRead($excelWorkbook, $worksheetName) if @error Then Exit EndIf return $result EndFunc Func CloseWorkBook($excelWorkbook) Local Const $scriptName = "ExcelHelpers.au3" $result = _Excel_BookClose( $excelWorkbook, False ) if @error Then Exit EndIf return $result EndFunc Func CloseExcel($oExcel) Local Const $scriptName = "ExcelHelpers.au3" $result = _Excel_Close( $oExcel) if @error Then Exit EndIf return $result EndFunc Running the newest version of autoit and office 2016.
Moderators JLogan3o13 Posted September 23, 2016 Moderators Posted September 23, 2016 The error is telling you the workbook object doesn't exist. If you are running this test multiple times as you mention, are you ensuring there is no Excel object left hanging around after you end? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
chobo2 Posted September 23, 2016 Author Posted September 23, 2016 How would I check. I do have all those @errors to check if the file had problems closing and such. The other funny thing is that I am running this on another computer and it works one difference I can see is that it is excel 2010.
Somerset Posted September 23, 2016 Posted September 23, 2016 You keep feeding it after midnight, don't you?
aiter Posted September 24, 2016 Posted September 24, 2016 (edited) One mistake I see is that you are not declaring $oExcel, $excelWorkBook and $newbidderRegWorksheet as global. Oh, I see you are passing the handles in. Never mind. This looks wrong If IsObj($oExcel) And @error Then Exit EndIf if @error then exit. You are getting function happy when the functions already exist for all operations. Make the handles global, lose the functions. Edited September 24, 2016 by aiter
water Posted September 24, 2016 Posted September 24, 2016 9 hours ago, Somerset said: You keep feeding it after midnight, don't you? How does this help to solve the problem My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted September 24, 2016 Posted September 24, 2016 chobo2, can you please tell us why you need those wrapper functions? I think they make the code much more complex but as I see do not serve any purpose. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
chobo2 Posted September 24, 2016 Author Posted September 24, 2016 11 hours ago, water said: chobo2, can you please tell us why you need those wrapper functions? I think they make the code much more complex but as I see do not serve any purpose. Logging(removed in example) and code re usability. I have to reuse this code many time over and over I don't want my test to have like 30 lines of all the same code, makes maintainability of tests alot harder.
chobo2 Posted September 24, 2016 Author Posted September 24, 2016 (edited) 12 hours ago, aiter said: One mistake I see is that you are not declaring $oExcel, $excelWorkBook and $newbidderRegWorksheet as global. Oh, I see you are passing the handles in. Never mind. This looks wrong If IsObj($oExcel) And @error Then Exit EndIf if @error then exit. You are getting function happy when the functions already exist for all operations. Make the handles global, lose the functions. I made the functions for code resuability as there is alot of checks to see if the object exists which I later log and such. I don't want to duplicate this code everytime I make a test(currently at 12 tests using this same code). Edited September 24, 2016 by chobo2
chobo2 Posted September 25, 2016 Author Posted September 25, 2016 I tried by removing all the functions and did this in all my scripts Local $oExcel = _Excel_Open() Local $fileName = @ScriptDir & "\Files\myExcel.xlsx" Local $excelWorkbook = _Excel_BookOpen($oExcel, $filename) $workSheet = _Excel_RangeRead($excelWorkbook, "Sheet1") _Excel_Close( $oExcel) Same error.
water Posted September 25, 2016 Posted September 25, 2016 When searching the forum for the error message you get 19 hits. I provided a solution for this problem here: My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
chobo2 Posted September 26, 2016 Author Posted September 26, 2016 (edited) 23 hours ago, water said: When searching the forum for the error message you get 19 hits. I provided a solution for this problem here: Thanks. It seems to have solved my issue on my local machine with Excel 2016 (but I am doing more testing) but on the other machine with Excel 2010 on it, now I get the exact same error. Seems like I can win. Should I be checking for something else to stop the error from popping up? So the script could try again or something. Edited September 26, 2016 by chobo2
water Posted September 26, 2016 Posted September 26, 2016 You are running the same version of AutoIt and try to open the same workbook on both machines? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
chobo2 Posted September 26, 2016 Author Posted September 26, 2016 2 hours ago, water said: You are running the same version of AutoIt and try to open the same workbook on both machines? Yep both are 3.3.14.2 and it is the same workbook. It works sometimes that is the thing that confuses me so much. It can run like 5 times in a row just fine, then the 6th time it dies with that error. I look at see and I can see no excel process running or anything.
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