Sign in to follow this  
Followers 0
ResNullius

[Solved] Vbs & Excel COM works, AutoIt doesn't

6 posts in this topic

#1 ·  Posted (edited)

Office 2003 on XP Pro SP3

The following vbs script functions as expected and returns the Author info for the excel file:

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Test.xls")
Wscript.Echo objWorkbook.BuiltinDocumentProperties("Author")
objExcel.quit

However, the following AutoIt script returns an empty string.

$oExcel = ObjCreate("Excel.Application")
$oWorkbook = $oExcel.Workbooks.Open("C:\Book1.xls")
MsgBox(0,"",$oWorkbook.BuiltinDocumentProperties("Author"))
$oExcel.quit

In fact, the value for any of the BuiltinDocumentProperties returned by the AutoIt script is empty.

What, if anything, am I doing wrong? :P

Edit: changed subject to [solved]

Edited by ResNullius

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Possibly not doing it the correct way but this seemed to work for me

$oExcel = ObjCreate("Excel.Application")
$oWorkbook = $oExcel.Workbooks.Open(@scriptDir & "\test.xls")
$oProperties = $oWorkbook.BuiltinDocumentProperties()
For $items in $oProperties
    If $items.Name = "Author" then MsgBox(0,"Author", $items.Value )
Next

$oExcel.Close
$oExcel.quit
Edited by ChrisL

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can get quite a lot of information out of it this way, I had to use the error handler in it because some items failed maybe because they need a different way of getting the data or .Value shouldbe an array maybe?

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); error handler

$oExcel = ObjCreate("Excel.Application")
$oWorkbook = $oExcel.Workbooks.Open(@scriptDir & "\test.xls")
$oProperties = $oWorkbook.BuiltinDocumentProperties()
For $items in $oProperties
    ConsoleWrite($items.Name & " = " & $items.Value &  @crlf)
Next

$oExcel.Close
$oExcel.quit


Func MyErrFunc() 
   $g_eventerror = 1; something to check for when this function returns 
Endfunc
Edited by ChrisL

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks ChrisL, works a treat.

Still, I wonder what the difference is in the way AutoIt deals with the collection... :P

Edit: Re: the errors http://msdn.microsoft.com/en-us/library/mi...rty(VS.80).aspx

If a given application doesn't define a value for one of the built-in document properties, returning the Value property for that document property causes an error.

Edited by ResNullius

Share this post


Link to post
Share on other sites

And here is how to modify the AutoIt script in my original post to work:

$oExcel = ObjCreate("Excel.Application")
$oWorkbook = $oExcel.Workbooks.Open("C:\Book1.xls")
MsgBox(0,"",$oWorkbook.BuiltinDocumentProperties("Author").Value)
$oExcel.quit

Share this post


Link to post
Share on other sites

And here is how to modify the AutoIt script in my original post to work:

$oExcel = ObjCreate("Excel.Application")
$oWorkbook = $oExcel.Workbooks.Open("C:\Book1.xls")
MsgBox(0,"",$oWorkbook.BuiltinDocumentProperties("Author").Value)
$oExcel.quit
Cool... I really didn't know what I was doing I just buggered about with it until I got some data out :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  
Followers 0