开发者

C# - Class not registered - creating a Excel spreadsheet with Macros using VBIDE

开发者 https://www.devze.com 2023-03-21 19:44 出处:网络
Using VS2010, I cannot use the VBIDE interop DLL. Could someone please see if they can reproduce on their PC - code straight out of http://support.microsoft.com/kb/303872

Using VS2010, I cannot use the VBIDE interop DLL. Could someone please see if they can reproduce on their PC - code straight out of http://support.microsoft.com/kb/303872

  1. Create winform app in C#.

  2. Reference these 2 DLLs: C:\Program Files\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Offic开发者_如何学Pythone14\Microsoft.Vbe.Interop.dll and C:\Program Files\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Office14\Microsoft.Office.Interop.Excel.dll

  3. In Form_load put this code:


//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)).


Working code:

VBIDE.VBComponent oModule;

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

精彩评论

暂无评论...
验证码 换一张
取 消