Himanshu Posted December 9, 2010 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
Juvigy Posted December 9, 2010 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.
water Posted December 9, 2010 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 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
Himanshu Posted December 10, 2010 Author 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??
Juvigy Posted December 10, 2010 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.
MWIDNER21 Posted February 22, 2011 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.
Juvigy Posted February 23, 2011 Posted February 23, 2011 Yes. You will have to do _ExcelBookOpen() again or edit the macro and remove the closing code there.
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