Jump to content

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


Recommended Posts

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

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

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

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