Jump to content

Excel 2010 ObjCreate


Zoomulator
 Share

Recommended Posts

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!

Link to comment
Share on other sites

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:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

Glad to be of service :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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