在VB.NET中创建Excel工作簿时出错

时间:2017-07-10 05:01:25

标签: excel vb.net visual-studio

我正在尝试使用Interop.Excel通过VB.Net打开Excel工作簿。我在项目中添加了引用,但是在运行时单击“导出”按钮时出现错误:

Runtime Error

如图所示,错误发生在我在下面的代码中指出的第25行:

Imports Excel = Microsoft.Office.Interop.Excel



 Public Class Form1


Dim xlApp As Excel.Application = New Excel.Application 'creating instance of excel app
Dim xlWb As Excel.Workbook
Dim xlSheet As Excel.Worksheet


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Form2.Show()




End Sub

Private Sub Export_Click(sender As Object, e As EventArgs) Handles Export.Click



    xlWb = xlApp.Workbooks.Add  'ERROR STARTS HERE (Line 25)
    xlSheet = xlWb.Sheets.Add

    If (xlApp Is Nothing) Then

        MsgBox("Excel is not installed on your system!")

    End If






    xlApp.Visible = True
    xlApp.UserControl = True

    xlApp = Nothing
    xlWb = Nothing
    xlSheet = Nothing


End Sub
End Class

当我重建程序时,我收到以下警告:

VBIDE Error

我觉得这与程序无关,但在Visual Studio中是一个问题,但我不确定,因为我之前从未遇到此错误,直到我制作此程序。

我已尝试过,正如其他论坛所建议的那样,重新安装Office 2013以及VS 2013,但一切都没有改变。

0 个答案:

没有答案