COM尝试创建Excel.Application对象时出错

时间:2016-06-16 09:22:51

标签: vb.net visual-studio-2013 excel-2016

使用Visual Studio 2013创建涉及excel的新程序。之前在earliere excel版本中完成此操作,但现在无法使其工作。 尝试创建excel应用程序对象会引发错误(但是当我查看任务管理器时会启动excel进程)。我们正在使用Office 365和Excel 2016.我已卸载Office并进行了全新安装,但仍然出现相同的错误。

拥有一个vb .net windows项目。我通过选择COM - 类型库添加了一个引用 - 并添加了Microsoft Excel 16.0对象库(版本1.9)。

代码是这样的:

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") 

抛出错误:

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

任何帮助将不胜感激。感谢。

0 个答案:

没有答案