COM Error trying to create Excel.Application object

0

Working from Visual Studio 2013 to create a new program involving excel. Done this before in earliere excel versions, but cannot get it to work now. Trying to create the excel application object throws an error (however an excel process is started when I look in the task manager). We're using Office 365 with Excel 2016. I have uninstalled Office and made a complete new installation, but still having the same error.

Having a vb .net windows project. I haved added a reference by choosing COM - Type Libraries - and added Microsoft Excel 16.0 Object Library (version 1.9).

Code is like this:

Imports Excel = Microsoft.Office.Interop.Excel

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim appXL As Excel.Application
        Dim wbXl As Excel.Workbook
        Dim shXL As Excel.Worksheet
        Dim raXL As Excel.Range

        ' Start Excel and get Application object.
        appXL = CreateObject("Excel.Application")
        appXL.Visible = True

appXL = CreateObject("Excel.Application") 

throws error :

An unhandled exception of type 'System.InvalidCastException' occurred in WindowsApplication3.exe
Additional information: 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).

I have checked registry editor in HKEY_CLASSES_ROOT - typelib and found the IID {000208D5-0000-0000-C000-000000000046}. It looks like this:
TypeLib               (Default)    REG_SZ   {00020813-0000-0000-C000- 000000000046} 
                       Version     REG_SZ    1.9

Any help will be much appreciated. Thanks.

vb.net
visual-studio-2013
excel-2016
asked on Stack Overflow Jun 16, 2016 by henke • edited Jun 16, 2016 by tarzanbappa

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0