在为其分配值之前使用的空例外错误'

时间:2012-10-20 15:18:53

标签: vb.net

我的代码中出现了一个null异常错误,我无法理解为什么。

我在'Resources'中添加了一个名为'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.

1 个答案:

答案 0 :(得分:1)

将它们声明为New实例

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