locked
Cannot create an instance of Excel 2016 in Visual Studio 2015 RRS feed

  • Question

  • <p style="padding-right:0px;padding-left:0px;border:0px;font-size:15px;clear:both;color:#222426;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;line-height:19.5px;">I have Visual Studio 2015 and my application is for .NET Framework 4.0.</p><p style="padding-right:0px;padding-left:0px;border:0px;font-size:15px;clear:both;color:#222426;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;line-height:19.5px;">I installed Microsoft Office Home&amp;Buissness 2016 and trying tocreate an instance using this code:&nbsp;<code style="margin:0px;padding:1px 5px;border:0px;font-size:13px;font-family:Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif;white-space:pre-wrap;background-color:#eeeeee;">Microsoft.Office.Interop.Excel.Application excelAppTemplate = new Microsoft.Office.Interop.Excel.Application();</code></p><p style="padding-right:0px;padding-left:0px;border:0px;font-size:15px;clear:both;color:#222426;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;line-height:19.5px;">but I get this error:</p><blockquote style="margin:0px 0px 10px;padding:10px;border-width:0px 0px 0px 2px;border-left-style:solid;border-left-color:#ffeb8e;font-size:15px;quotes:none;color:#222426;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;line-height:19.5px;background-color:#fff8dc;"><p style="margin-bottom:0px;padding-right:0px;padding-left:0px;border:0px;clear:both;">Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.Office.Interop.Excel.Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155).</p></blockquote><p style="padding-right:0px;padding-left:0px;border:0px;font-size:15px;clear:both;color:#222426;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;line-height:19.5px;">I am referencing Microsoft.Office.Interop.Excel 15.0.0.0. While searching for answers, I have seen a solution to delete this registry key:</p><blockquote style="margin:0px 0px 10px;padding:10px;border-width:0px 0px 0px 2px;border-left-style:solid;border-left-color:#ffeb8e;font-size:15px;quotes:none;color:#222426;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;line-height:19.5px;background-color:#fff8dc;"><p style="margin-bottom:0px;padding-right:0px;padding-left:0px;border:0px;clear:both;">HKEY_CLASSES_ROOT\TypeLib{00020813-0000-0000-C000-000000000046}</p></blockquote><p style="padding-right:0px;padding-left:0px;border:0px;font-size:15px;clear:both;color:#222426;font-family:Arial, 'Helvetica Neue', Helvetica, sans-serif;line-height:19.5px;">But I have 1.9 and not the previous version like 1.8 or 1.7, just 1.9. Is there any new version for Office 2016?</p>
    Tuesday, April 5, 2016 9:35 AM

Answers