Jump to content

Error while trying to read from excel file: Variable must be of type "Object"


Go to solution Solved by lijrobert,

Recommended Posts

So I started working on a script to parse so data from and .xls file, but I've reached a little error. After copying a lot of the code from some of the example scripts, I'm getting this error

Variable must be of type "Object".:
$wfData = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A"), 1)
$wfData = _Excel_RangeRead($oWorkbook, Default, $oWorkbook^ ERROR

Here is my code:

#include <Excel.au3>
#include <Array.au3>
#include "Zip.au3"
Const $filePath = @ScriptDir & "\Workfiles.xls"
Const $captPath = @ScriptDir & "\IECapt.exe"
$startScriptTest = FileExists($filePath)
$startScriptTest = FileExists($captPath)
if Not $startScriptTest Then
   MsgBox(0,"Error","You do not have all the required files in the directory with the exectuable. Please read the readme")
EndIf
$oAppl = _Excel_Open()
$oWorkbook = _Excel_BookOpen($oAppl, $filePath)
$wfData = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A"), 1)

Sorry if this is something I'm missing in the documentation, but I've read it several times with no improvement

Edited by lijrobert
Link to comment
Share on other sites

  • Moderators

Hi, lijrobert, welcome to the forum. The code you have works for me, as I can see the contents of column A returned (remember it is returned as an array). I don't have your Zip.au3, or your IECapt.exe, so I stripped your script down a bit, but this works fine:

#include <Array.au3>
#include <Excel.au3>
#include <Array.au3>
;#include "Zip.au3"

Const $filePath = @ScriptDir & "\Workfiles.xls"
;Const $captPath = @ScriptDir & "\IECapt.exe"
$startScriptTest = FileExists($filePath)
;$startScriptTest = FileExists($captPath)
    if Not $startScriptTest Then MsgBox(0,"Error","You do not have all the required files in the directory with the exectuable. Please read the readme")


$oAppl = _Excel_Open()
$oWorkbook = _Excel_BookOpen($oAppl, $filePath)
$wfData = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A"), 1)
    _ArrayDisplay($wfData)

Just out of curiosity, what version of AutoIt are you using?

"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

Hi, lijrobert, welcome to the forum. The code you have works for me, as I can see the contents of column A returned (remember it is returned as an array). I don't have your Zip.au3, or your IECapt.exe, so I stripped your script down a bit, but this works fine:

#include <Array.au3>
#include <Excel.au3>
#include <Array.au3>
;#include "Zip.au3"

Const $filePath = @ScriptDir & "\Workfiles.xls"
;Const $captPath = @ScriptDir & "\IECapt.exe"
$startScriptTest = FileExists($filePath)
;$startScriptTest = FileExists($captPath)
    if Not $startScriptTest Then MsgBox(0,"Error","You do not have all the required files in the directory with the exectuable. Please read the readme")


$oAppl = _Excel_Open()
$oWorkbook = _Excel_BookOpen($oAppl, $filePath)
$wfData = _Excel_RangeRead($oWorkbook, Default, $oWorkbook.ActiveSheet.Usedrange.Columns("A:A"), 1)
    _ArrayDisplay($wfData)

Just out of curiosity, what version of AutoIt are you using?

I'm using v3.3.12.0. 

Link to comment
Share on other sites

  • Moderators

And the workbook is opening successfully for you, if you comment out the $wfData line? I am unable to get your script to fail.

"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

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