Jump to content

_ExcelReadArray give object failed error


Recommended Posts

Hello,

I am using the function "_ExcelReadArray" of an Excel UDF (ExcelCom_UDF.au3). The code of the function is :

;===============================================================================
;
; Description:      Create an array from a row or column of the active worksheet.
; Syntax:           $array = _ExcelReadArray($oExcel, $iStartRow, $iStartColumn, $iNumCells, $iDirection = 0, $iIndexBase = 0)
; Parameter(s):     $oExcel - Excel object opened by a preceding call to _ExcelBookOpen() or _ExcelBookNew()
;                   $iStartRow - The table row to start reading the array from
;                   $iStartColumn - The table column to start reading the array from
;                   $iNumCells - The number of cells to read into the array
;                   $iDirection - The direction of the cells to read into array (0=right, 1=down)
;                   $iIndexBase - Specify whether array created is to have index base of either 0 or 1
; Requirement(s):   None
; Return Value(s):  On Success - Returns an array with the specified cell contents
;                   On Failure - Returns 0 and sets @error on errors:
;                       @error=1 - Specified object does not exist
;                       @error=2 - Parameter out of range
;                           @extended=0 - Row out of range
;                           @extended=1 - Column out of range
;                       @error=3 - Invalid number of cells
;                       @error=4 - Invalid direction parameter
; Author(s):        SEO <locodarwin at yahoo dot com>
; Note(s):          None
;
;===============================================================================
Func _ExcelReadArray($oExcel, $iStartRow, $iStartColumn, $iNumCells, $iDirection = 0, $iIndexBase = 0)
    Local $aArray[$iNumCells + $iIndexBase]
    If NOT IsObj($oExcel) Then Return SetError(1, 0, 0)
    If $iStartRow < 1 Then Return SetError(2, 0, 0)
    If $iStartColumn < 1 Then Return SetError(2, 1, 0)
    If NOT IsNumber($iNumCells) Or $iNumCells < 1 Then Return SetError(3, 0, 0)
    If $iDirection < 0 Or $iDirection > 1 Then Return SetError(4, 0, 0)
    If NOT $iDirection Then
       ;_ExcelSheetActivate($oExcel, $oExcel.Activesheet.Name)
        For $xx = $iIndexBase To Ubound($aArray) - 1
            $aArray[$xx] = $oExcel.Activesheet.Cells($iStartRow, ($xx - $iIndexBase) + $iStartColumn).Value
        Next
     Else
        ;_ExcelSheetActivate($oExcel, $oExcel.Activesheet.Name)
        For $xx = $iIndexBase To Ubound($aArray) - 1
            $aArray[$xx] = $oExcel.Activesheet.Cells(($xx - $iIndexBase) + $iStartRow, $iStartColumn).Value
        Next
    EndIf
    If $iIndexBase Then $aArray[0] = Ubound($aArray) - 1
    Return $aArray
EndFunc ;==>_ExcelReadArray

When I want to call this function a few times after eachother it suddenly gives me error message "The requested action of this object has failed

$aArray[$xx] = $oExcel.Activesheet.Cells(($xx - $iIndexBase) + $iStartRow, $iStartColumn).Value

$aArray[$xx] = $oExcel.Activesheet.^ ERROR 

 

I also tried "$aArray[$xx] = $oExcel.ActiveWorkBook.Activesheet.Cells(($xx - $iIndexBase) + $iStartRow, $iStartColumn).Value but this is also a nogo

 

Any idea's why it's giving me the error after running the function a few times.

 

Thanks for the respons,

 

Rodger

 

Edited by Rodger
Link to comment
Share on other sites

Seems you are running a very old version of AutoIt. The Excel UDF has been rewritten to support newer versions of Excel and to enhance  performance.
I suggest to upgrade - if possible.

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

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