Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Excel 2010 ObjCreate


  • Please log in to reply
10 replies to this topic

#1 Zoomulator

Zoomulator

    Seeker

  • Active Members
  • 6 posts

Posted 15 November 2011 - 01:36 PM

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!







#2 water

water

    ?

  • MVPs
  • 15,305 posts

Posted 15 November 2011 - 01:46 PM

IIRC if you run the 32bit version of Office you have to run the AutoIt script as 32bit.
Insert
at the top of your script.
UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#3 Zoomulator

Zoomulator

    Seeker

  • Active Members
  • 6 posts

Posted 15 November 2011 - 02:40 PM

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, 15 November 2011 - 02:40 PM.


#4 water

water

    ?

  • MVPs
  • 15,305 posts

Posted 15 November 2011 - 02:46 PM

Can you start Excel manually?
Maybe a COM error handler will give you more information:
AutoIt         
#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)
UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#5 Zoomulator

Zoomulator

    Seeker

  • Active Members
  • 6 posts

Posted 15 November 2011 - 02:55 PM

Neat!


Here's the result:
Posted Image


does that make sense at all?

#6 water

water

    ?

  • MVPs
  • 15,305 posts

Posted 15 November 2011 - 02:58 PM

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?
UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#7 Zoomulator

Zoomulator

    Seeker

  • Active Members
  • 6 posts

Posted 15 November 2011 - 03:15 PM

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?

#8 water

water

    ?

  • MVPs
  • 15,305 posts

Posted 15 November 2011 - 03:22 PM

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?
UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#9 Zoomulator

Zoomulator

    Seeker

  • Active Members
  • 6 posts

Posted 15 November 2011 - 03:36 PM

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!

#10 water

water

    ?

  • MVPs
  • 15,305 posts

Posted 15 November 2011 - 03:37 PM

Glad to be of service :D
UDFs:
Active Directory (NEW 2014-07-21 - Version 1.4.1.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2014-07-27 - Version 1.0.0.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2013-01-21 - Version 0.3.1.1) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
Tutorials:
ADO - Wiki

#11 Zoomulator

Zoomulator

    Seeker

  • Active Members
  • 6 posts

Posted 15 November 2011 - 04:07 PM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users