トップ回答者
Cannot create ActiveX component Excel

質問
-
VB.NET
Dim oExcel As Object = Nothing
oExcel = CreateObject("Excel.Application") ' -> Cannot create ActiveX Component
In my project, I don't reference any Excel DLL. This has been working fine for several years.
Now I am on Win 7, VS 2005 and Office 2010 (32-bit) and I get this error.
I tried to add a reference to Microsoft.Office.Interop.Excel but can't find anything under the .NET tab... Turns out I have a program that has a copy of the DLL (office 12) so I copy the DLL to my program's directory and add a reference through the Browse Button.
My code is now:
Dim oExcel As New Microsoft.Office.Interop.Excel.Application
System.InvalidCastException was unhandled by user code
Message="Creating an instance of the COM component with CLSID {00024500-0000-0000-C000-000000000046} from the IClassFactory failed due to the following error: 80004002."
I am baffled.
1. Microsoft.Office.Interop.Excel is in the GAC. How come it is not available under the .NET tab?
2. How come the object can't be created?
Any help would be appreciated.
2010年7月31日 1:24
回答
すべての返信
-
Hi Atchoum
The version of Office you want to automate must match the version of the PIA installed on the machine. If Office 2010 is installed, then you can't use the DLL for an earlier version.
You do need the PIA you found in the GAC. If it's not listed in the .NET tab, look in the COM tab. The Office applications are COM, so by default, that's where they're listed. If VSTO 2008 or 2010 is installed, then VSTO takes care of writing entries to the .NET tab. But that won't be the case with Visual Studio 2005.
Cindy Meister, VSTO/Word MVP2010年7月31日 12:20 -
Hi Cindy,
Thanks for your response. I did find it under the COM tab. So that' one mystery solved. I learned something about VS2005. Thanks again.
Unfortunately I still get the following error.
System.InvalidCastException was unhandled by user code
Message="Creating an instance of the COM component with CLSID {00024500-0000-0000-C000-000000000046} from the IClassFactory failed due to the following error: 80004002."
Could it be a security issue? I am a single user, administrator of course. I have NIS 2010 installed, turned everything off I believe to no avail. I run Excel as an administrator...
Atchoum
2010年7月31日 13:52 -
2010年8月2日 7:15
-
Hi Peter,
No, I can't. I can't even trap the error. Excel just crashes. Among the info that it wants to send to Microsoft, in the InternalMetadata.xml, I could pick up:
<ProblemSignatures>
<EventType>APPCRASH</EventType>
<Parameter0>EXCEL.EXE</Parameter0>
<Parameter1>14.0.4756.1000</Parameter1>
<Parameter2>4b9c08e8</Parameter2>
<Parameter3>StackHash_d9ab</Parameter3>
<Parameter4>6.1.7600.16559</Parameter4>
<Parameter5>4ba9b29c</Parameter5>
<Parameter6>c0000374</Parameter6>
<Parameter7>000cdc9b</Parameter7>
</ProblemSignatures>
Atchoum
2010年8月2日 9:40