标题:利用vb.net操作excel2010时,出现异常错误,如何修改?
取消只看楼主
hong1978
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-1-23
 问题点数:0 回复次数:0 
利用vb.net操作excel2010时,出现异常错误,如何修改?
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Core

Public Class Form1
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

            Dim myapp As Excel.Application
            Dim mybook As Excel.Workbook
            Dim mysheet As Excel.Worksheet
            Dim filename As String

            filename = "E:\vb2010\4\13.xlsx"
            myapp = CreateObject("Excel.application")
            myapp.Visible = False
            mybook = myapp.Workbooks.Open(filename)
            mysheet = mybook.Worksheets("sheet1")

            myapp.Quit()
            mysheet = Nothing
            mybook = Nothing
            myapp = Nothing
   
    End Sub
End Class
运行时出现错误:
   检查异常的ErrorCode 属性以确定COM对象返回的HRESULT.

[此贴子已经被作者于2021-11-5 09:01编辑过]

搜索更多相关主题的帖子: 错误 异常 Dim 出现 Excel 
2021-11-05 08:59



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-507398-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.176883 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved