Excel 2010 ObjCreate
Posted 15 November 2011 - 01:36 PM
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!
Posted 15 November 2011 - 02:40 PM
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.
Posted 15 November 2011 - 02:46 PM
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)
Posted 15 November 2011 - 02:58 PM
$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?
Posted 15 November 2011 - 03:15 PM
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?
Posted 15 November 2011 - 03:22 PM
The link you specified mentions that he needed to install Office using the MSI method to make it work:
if you check the registry do you find an entry for HKEY_CLASSES_ROOT\Excel.Application?
"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..."
Posted 15 November 2011 - 03:36 PM
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!
Posted 15 November 2011 - 04:07 PM
Microsoft sure knows how to make things not work and leave a minimum amount of trace behind to fix it.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users