Sign in to follow this  
Followers 0
Himanshu

Excel.au3 Error: Variable must be of type "Object"

7 posts in this topic

#1 ·  Posted (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   ;==>_ExcelReadCell

Kindly help me out. What should be done??

Please note that I am nowhere in my script using an object.

Edited by Himanshu

Share this post


Link to post
Share on other sites



$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

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

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

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

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

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0