Jump to content

Excel Dies and I don't know why?


chobo2
 Share

Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

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!

Link to comment
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.

 

Link to comment
Share on other sites

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
Link to comment
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 (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
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 (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
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. 

Link to comment
Share on other sites

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
Link to comment
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 (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
Share on other sites

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
Link to comment
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 (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

 

Link to comment
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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...