0

我的代码中有一个空异常错误,我不明白为什么。

我在“资源”中的项目中添加了一个名为“FilterXpath”的 excel 文件。我有以下代码:

Dim FilterXpath As Microsoft.Office.Interop.Excel.Application
Dim w As Microsoft.Office.Interop.Excel.worksheet
Dim sheet As Worksheet

w = FilterXpath.Workbooks.Open("C:\Users\sridevi\Documents\Visual Studio 2008\Projects\WindowsApplication2\WindowsApplication2\Resources\FilterXpath.xlsx")
''I got null exception here stating that FilterXpath is used before it has been assigned a value.
4

1 回答 1

1

将它们声明为New实例

Dim FilterXpath As New Microsoft.Office.Interop.Excel.Application 
Dim w As New Microsoft.Office.Interop.Excel.worksheet Dim sheet As Worksheet
于 2012-10-20T15:20:40.460 回答