Himanshu 0 Posted December 9, 2010 (edited) Hi!!I have a script wherein I open a preexisting Excel Workbook using the _ExcelBookOpen() command.There comes a point in the script execution where the script is paused and i am required to (manually) open another instance of MS Excel this time to read a .csv file.After the work of the .csv file is done I close it.Now when i restart my script it ends giving an error in the file Excel.au3 as: Variable must be of type "Object".Func _ExcelReadCell($oExcel, $sRangeOrRow, $iColumn = 1) If Not IsObj($oExcel) Then Return SetError(1, 0, 0) If Not StringRegExp($sRangeOrRow, "[A-Z,a-z]", 0) Then If $sRangeOrRow < 1 Then Return SetError(2, 0, 0) If $iColumn < 1 Then Return SetError(2, 1, 0) Return $oExcel.Activesheet.Cells($sRangeOrRow, $iColumn).Value ;-----> This where the Error points to! Else Return $oExcel.Activesheet.Range($sRangeOrRow).Value EndIf EndFunc ;==>_ExcelReadCellKindly help me out. What should be done??Please note that I am nowhere in my script using an object. Edited December 9, 2010 by Himanshu Share this post Link to post Share on other sites
Juvigy 49 Posted December 9, 2010 $oExcel. should be an object. You get the error because it is not. Put an IsObj() check to verify and take action. Share this post Link to post Share on other sites
water 2,388 Posted December 9, 2010 Hi!!I have a script wherein I open a preexisting Excel Workbook using the _ExcelBookOpen() command.There comes a point in the script execution where the script is paused and i am required to (manually) open another instance of MS Excel this time to read a .csv file.After the work of the .csv file is done I close it.Now when i restart my script it ends giving an error in the file Excel.au3 as: Variable must be of type "Object".Be sure that you don't close the Excel instance when you just want to close the workbook where you handled the .csv file.When I start Excel using _ExcelBookOpen() there is one instance of EXCEL.EXE in the task manager. When I open another workbook there are two icons in the task bar but still only one EXCEL.EXE.So be sure that Excel is still running after you close your .csv file.I'm running Windows XP and Office XP so your system might behave differently. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX (NEW 2020-12-15 - Version 1.6.3.1) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2020-06-27 - Version 1.3.2.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsPowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & SupportExcel - Example Scripts - WikiWord - WikiTask Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - WikiTutorials:ADO - Wiki, WebDriver - Wiki Share this post Link to post Share on other sites
Himanshu 0 Posted December 10, 2010 Be sure that you don't close the Excel instance when you just want to close the workbook where you handled the .csv file.When I start Excel using _ExcelBookOpen() there is one instance of EXCEL.EXE in the task manager. When I open another workbook there are two icons in the task bar but still only one EXCEL.EXE.So be sure that Excel is still running after you close your .csv file.I'm running Windows XP and Office XP so your system might behave differently.Hey thanks a lot water!!It worked. Now my script doesn't get exited after i close the instance of .csv file.However, by mistake, if i close other instances of EXCEL.EXE then this problem might/should reoccur.Is there any way that i could know which instance of EXCEL.EXE is for .csv file? If i come to know about that then i'll be able to incorporate it in my script. Can knowing its pid help?? Do all the instances of EXCEL.EXE have same pids or different?? Share this post Link to post Share on other sites
Juvigy 49 Posted December 10, 2010 There is an option in excel to open every file in a new instance. That way when you open the csv it will open another instance in Excel (2 excel.exe processes in task manager) so when you close it it wont affect your program. Share this post Link to post Share on other sites
MWIDNER21 0 Posted February 22, 2011 Hello, I have the same error but all I want to do is open an Excel document that has a macro inside that does everything for me and also closes Excel. If I use the _ExcelBookOpen() commmand and have the macro do it's thing and then it closes the document, I get the error described above. I did the test with the IsObj() and it does create an object. Is it getting an error because I'm using autoit to open it and it is closing itself by other means and not using _ExcelBookClose()? Thank you. Share this post Link to post Share on other sites
Juvigy 49 Posted February 23, 2011 Yes. You will have to do _ExcelBookOpen() again or edit the macro and remove the closing code there. Share this post Link to post Share on other sites