我的代码中出现了一个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.
答案 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