chobo2

Excel Dies and I don't know why?

14 posts in this topic

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)
Func 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.

error.JPG

Share this post


Link to post
Share on other sites



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?


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

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.

 

Share this post


Link to post
Share on other sites

You keep feeding it after midnight, don't you?


 

Spoiler

shoot_zpsfd329d66.png
dontbelieveeverythingyouthink_zps0e1e900

Madness is the first step to understanding...

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by aiter

Share this post


Link to post
Share on other sites
9 hours ago, Somerset said:

You keep feeding it after midnight, don't you?

How does this help to solve the problem :huh:


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
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. 

Share this post


Link to post
Share on other sites

#9 ·  Posted (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 by chobo2

Share this post


Link to post
Share on other sites

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 (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (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 by chobo2

Share this post


Link to post
Share on other sites

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 (2016-08-18 - Version 1.4.6.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2016-12-04 - Version 1.2.2.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
Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
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.

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