Jump to content
Sign in to follow this  
lijrobert

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

Recommended Posts

lijrobert

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

Share this post


Link to post
Share on other sites
JLogan3o13

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?


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
lijrobert

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. 

Share this post


Link to post
Share on other sites
JLogan3o13

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


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
lijrobert

Just realized I don't have excel installed. Guess I need that :P 

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  

×