2011-07-20 97 views
1

使用VS2010,我無法使用VBIDE interop DLL。可能有人請看看他們是否可以複製其PC上 - 碼連續出http://support.microsoft.com/kb/303872C# - 未註冊的類 - 使用VBIDE創建帶有宏的Excel電子表格

  1. 創建C#winform應用程序。

  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 

Retrieving the COM class factory for component with CLSID {BE39F3DA-1B13-11D0-887F-00A0C90F2744} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

+0

woops的代碼錯誤從KB文章...現在我得到「編程訪問Visual Basic項目是不可信的」 –

回答

1

工作代碼:

VBIDE.VBComponent oModule; 

oModule = excelWorkbook.VBProject.VBComponents.Add(VBIDE.vbext_ComponentType.vbext_ct_StdModule); 
相關問題