Sign in to follow this  
Followers 0

Excel 2010 ObjCreate

11 posts in this topic

#1 ·  Posted

I've been trying for so many hour to get an activeX handle to Excel 2010 to work.

First I tried to do it with the WSH using the WScript.CreateObject( "Excel.Application" )

but for some reason it throws an error and says "Could not locate automation class named 'Excel.Application'.", although every example I've seen does it exactly like so.

Tried searching on google about the error but failed to find anything of relevance.

So I thought I'd try to turn to AutoIt. I've read through the help document, ran a few scripts and it's pretty much the same. I've tried a bunch of different examples with Excel, but none of them work!

ObjCreate and ObjGet won't return a valid object with "Excel.Application"! Have I missed some not-so-obvious crucial setting somewhere? It seems close to impossible to find anything on google about it anyway. At least I can't find anything after several hours.

I'm using Windows 7 x64 if that matters at all.

All I want to do with excel is to navigate the cells in a document and paste in some values. Although it's gonna be a few thousand times, hence the need for a script.

Any help is highly appreciated!

Share this post


Link to post
Share on other sites



#2 ·  Posted

IIRC if you run the 32bit version of Office you have to run the AutoIt script as 32bit.

Insert

#AutoIt3Wrapper_UseX64= N
at the top of your script.

My UDFs and Tutorials:

UDFs:
Active Directory (NEW 2015-08-07 - Version 1.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (NEW 2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for the reply!

I do run the 32bit version. I inserted that line in the script, but no change. I tried both running and compiling the script as X86 aswell, but no go.

I've just copy pasted from the AutoIt help file, "Obj/COM reference" where there's a snipped for Excel.

This is what it looks like now:

#AutoIt3Wrapper_UseX64= N
$oExcel = ObjCreate( "Excel.Application")
if @error Then
  Msgbox (0,"ExcelTest","Error Getting an active Excel Object. Error code: " & hex(@error,8))
exit
endif
$oExcel.Visible = 1
$oExcel.WorkBooks.Add
$oExcel.ActiveWorkBook.ActiveSheet.Cell(1,1).Value = "test"
Edited by Zoomulator

Share this post


Link to post
Share on other sites

#4 ·  Posted

Can you start Excel manually?

Maybe a COM error handler will give you more information:

#AutoIt3Wrapper_UseX64= N
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")    ; Initialize a COM error handler
$oExcel = ObjCreate("Excel.Application")
if @error Then
  Msgbox (0,"ExcelTest","Error Getting an active Excel Object. Error code: " & hex(@error,8))
exit
endif
$oExcel.Visible = 1
$oExcel.WorkBooks.Add
$oExcel.ActiveWorkBook.ActiveSheet.Cells(1,1).Value = "test"


; This is my custom defined error handler
Func MyErrFunc()

  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"    & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "       & @TAB & hex($oMyError.number,8)  & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )

Endfunc

BTW: It should be Cells(1,1)


My UDFs and Tutorials:

UDFs:
Active Directory (NEW 2015-08-07 - Version 1.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (NEW 2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

Share this post


Link to post
Share on other sites

#5 ·  Posted

Neat!

Here's the result:

Posted Image

does that make sense at all?

Share this post


Link to post
Share on other sites

#6 ·  Posted

That's the same error I get when I call

$oExcel = ObjCreate("xxx")

Maybe there is a problem with this Office installation.

Can you start Excel by hand on this machine?

If yes, can you test your script on another machine where Office is installed?


My UDFs and Tutorials:

UDFs:
Active Directory (NEW 2015-08-07 - Version 1.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (NEW 2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

Share this post


Link to post
Share on other sites

#7 ·  Posted

Yes, starting Excel manually isn't a problem. Unfortunately, I've only got a single computer licence for office so I can't try it out anywhere else.

I've tried ObjGet( "", "Excel.Application" ) while office was running, and it gives the same error.

Found some vague information: http://stackoverflow.com/questions/3189641/invalid-class-string-using-excel-2010

I guess excel has failed to put the right entry in the registry?

Share this post


Link to post
Share on other sites

#8 ·  Posted

I too have Excel 2010 and

ObjCreate("Excel.Application")
and
ObjCreate("Excel.Application.14")
both work fine here.

The link you specified mentions that he needed to install Office using the MSI method to make it work:

"Okay, I figured it out. I installed Office 2010 using the new Click-to-run method (because I downloaded the trial from MS' web site using the default option). As soon as I download & install it using the MSI, all PROGID/CLSID are now in the registry (Excel.Application and Excel.Application.14) and my Automation works fine..."

if you check the registry do you find an entry for HKEY_CLASSES_ROOT\Excel.Application?

My UDFs and Tutorials:

UDFs:
Active Directory (NEW 2015-08-07 - Version 1.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (NEW 2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

Share this post


Link to post
Share on other sites

#9 ·  Posted

It's missing alright!

And I did use the click-and-run when I installed it a few months back. So I've uninstalled it and now I'm downloading the MSI. 1GB is insane... how bloated can software get now days anyway?

Oh well, I'll keep you posted. Thanks for all the help so far!

Share this post


Link to post
Share on other sites

#10 ·  Posted

Glad to be of service :D


My UDFs and Tutorials:

UDFs:
Active Directory (NEW 2015-08-07 - Version 1.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (NEW 2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

Share this post


Link to post
Share on other sites

#11 ·  Posted

Hah, that did the trick! (Re-installing using the msi instead of click-and-run)

Microsoft sure knows how to make things not work and leave a minimum amount of trace behind to fix it.

Thanks again

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