无效的强制转换异常VB.NET错误 [英] Invalid cast exception VB.NET error

查看:114
本文介绍了无效的强制转换异常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?


这篇关于无效的强制转换异常VB.NET错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆