locked
Cannot create ActiveX component Excel RRS feed

  • 質問

  • 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

回答

  • Peter,

    Thanks a million time. Following the result of your test I completely uninstalled Office and reinstalled and it solved the issue.

    Thanks for everybody's help on this.

     

    Atchoum

    • 回答としてマーク Atchoum21 2010年8月2日 9:54
    2010年8月2日 9:53

すべての返信

  • 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 MVP
    2010年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
  • What happens if you try like this:

    Dim xl as Excel.Application = new Excel.Application()

    Is there a reason you want/need to declare it as type Object?


    Cindy Meister, VSTO/Word MVP
    2010年8月1日 10:55
  • Hi Cindy,

    It does not make any difference: same error...

    Atchoum

    2010年8月1日 13:28
  • Does this help?

    http://support.microsoft.com/kb/306682/en-us

     

    2010年8月1日 19:35
  • Thanks but no.

    My code fails on the first line whether

     

    Dim xl as Excel.Application = new Excel.Application()

    or 

     Dim oExcel As Microsoft.Office.Interop.Excel.ApplicationClass
     oExcel = CreateObject("Excel.Application")

     


    2010年8月1日 20:52
  • Ok, so you are using Excel 2007, right. 

    Dim xlApp As Excel.Application

    When you use it...

    Set xlApp = New Excel.Application
    xlApp.Visible = True

    ...

    I've use this before:

    xlApp.Workbooks.Application.CalculateFull

    ...when you're done with it...

    xlApp.Quit

     

     

    2010年8月1日 20:58
  • I am using Excel 2010 and as said before the problem is I can't initialize the Excel object.

     

    2010年8月1日 21:01
  • Can you create an Excel instance using VBA in say Word or even Excel itself to start a second instance, eg

    Sub Test()
    Dim oXL As Object

    Set oXL = CreateObject("excel.application")
    oXL.Visible = True
    Set oWB = oXL.Workbooks.Add

    End Sub

    Regards,
    Peter Thornton

    • 回答としてマーク Atchoum21 2010年8月2日 9:54
    • 回答としてマークされていない Atchoum21 2010年8月2日 9:54
    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
  • Peter,

    Thanks a million time. Following the result of your test I completely uninstalled Office and reinstalled and it solved the issue.

    Thanks for everybody's help on this.

     

    Atchoum

    • 回答としてマーク Atchoum21 2010年8月2日 9:54
    2010年8月2日 9:53