无效的强制转换异常VB.NET错误

问题描述:

Imports Excel = Microsoft.Office.Interop.Excel
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

        Select Case ComboBox1.SelectedItem

            Case "Open Excel"

                Dim oExcel As New Microsoft.Office.Interop.Excel.Application()
                Dim oBook As Excel.WorkbookClass
                Dim oBooks As Excel.WorkbookClass
                Dim Open As New Excel.ApplicationClass

                'Start Excel and open the workbook
                oExcel.Visible = True
                'oBooks = oExcel.Workbooks

                oBook = oExcel.Workbooks.Open("H:\ExportExcelBook.xlsm")





美好的一天!我在



Good day! I have an error of InvalidCastException was unhandled at

oBook = oExcel.Workbooks.Open("H:\ExportExcelBook.xlsm")

我可以打开那个工作簿但是之后程序给了我这个问题。我正在使用Microsoft Visual Studio来运行此程序。我可以知道如何解决这个问题吗?



我尝试了什么:



添加引用,但我不确定在这种情况下缺少哪个引用。

I'm able to open up that workbook but the program gave me this issue after that. I'm using Microsoft Visual Studio to run this program. May I know how to solve this problem?

What I have tried:

Adding references but I'm not sure which reference is missing in this case.

oBook被声明为WorkBookClass [ ^ ]。如果你去那个文档,你会看到第一行说
oBook is declared as a WorkBookClass[^]. If you go to that documentation you will see the very first line says
Quote:

保留供内部使用。

使用工作簿 - 是 Workbooks.Open [ ^ ]返回

Use a Workbook - which is what Workbooks.Open[^] returns


我已在此处回答您的问题:错误missingmemberexception未得到处理 [ ^ ]

我确实提供了2个你必须访问的MSDN文档的链接。不是吗?
I already answered your question here: Error of missingmemberexception was unhandled[^]
And i did provide 2 links to MSDN documentation you have to visit. Don't you?