Search code examples
c#exceloffice-interopoffice-2013vba

Microsoft.Office.Interop.Excel not registered DLL


using the Microsoft.Office.Interop.Excel.dll leads to the following error:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Additional information: Retrieving the COM class factory for component with CLSID {00020819-0000-0000-C000-000000000046} failed due to the following error: 80040154 Klasse nicht registriert (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

The error occures in the fourth line of this code:

 using EX = Microsoft.Office.Interop.Excel;

 private void LoopBANFDokumenteLibrary(System.Uri Link)
 {
        EX.Application MSExcel = new EX.Application();
        EX.Workbook WB = MSExcel.Workbooks.Add(new EX.Workbook()); //ERROR: Exception thrown
        EX.Worksheet WS = WB.Worksheets.Add(new EX.Worksheet());
        /*...and further code...*/
 }

Some years ago, I used this Interop.Excel.DLL daily and a never had this problem. Opening regedit.exe, the dll is registered as you can see on this screenshot:

regedit

Does anybody has an idea, whats wrong?

Regards and thank you, Jan


Solution

  • Change

    EX.Workbook WB = MSExcel.Workbooks.Add(new EX.Workbook());
    

    to

    EX.Workbook WB = MSExcel.Workbooks.Add();
    

    Similarly use

    EX.Worksheet WS = WB.Worksheets.Add();