C# – 未注册的类 – 使用VBIDE创build一个包含macros的Excel电子表格

使用VS2010,我不能使用VBIDE interop DLL。 有人可以请看看他们是否可以在他们的PC上重现代码 – 直接从http://support.microsoft.com/kb/303872

  1. 在C#中创buildwinform应用程序。

  2. 引用这2个DLL: C:\Program Files\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Vbe.Interop.dllC:\Program Files\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Excel.dll

  3. 在Form_load把这个代码:


 //Using statments using Excel = Microsoft.Office.Interop.Excel;  using VBIDE = Microsoft.Vbe.Interop; using System.Reflection; Excel.Application excelApp = null; Excel._Workbook excelWorkbook; Excel._Worksheet excelSheet; excelApp = new Excel.Application(); excelApp.Visible = true; excelWorkbook = (Excel._Workbook)(excelApp.Workbooks.Add(Missing.Value)); excelSheet = (Excel._Worksheet)excelWorkbook.ActiveSheet; VBIDE.VBComponent oModule = new VBIDE.VBComponent(); //<--BAM throws an error 

检索具有CLSID {BE39F3DA-1B13-11D0-887F-00A0C90F2744}的组件的COM类工厂失败,原因如下:80040154类未注册(exception来自HRESULT:0x80040154(REGDB_E_CLASSNOTREG))。

工作代码:

 VBIDE.VBComponent oModule; oModule = excelWorkbook.VBProject.VBComponents.Add(VBIDE.vbext_ComponentType.vbext_ct_StdModule);