使用VS2010,我無法使用VBIDE interop DLL。可能有人請看看他們是否可以複製其PC上 - 碼連續出http://support.microsoft.com/kb/303872C# - 未註冊的類 - 使用VBIDE創建帶有宏的Excel電子表格
創建C#winform應用程序。
參考這2個DLL文件:
C:\Program Files\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Vbe.Interop.dll
和C:\Program Files\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Excel.dll
在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)).
woops的代碼錯誤從KB文章...現在我得到「編程訪問Visual Basic項目是不可信的」 –