2012-10-20 42 views
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. 

回答

1

聲明爲New例如

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

感謝advise.but還是我得到COM組件在該行「點心FilterXpath讀取錯誤80040154作爲新Microsoft.Office .Interop.Excel.Application' – user1724956

+0

對於此錯誤,請檢查此線程http://stackoverflow.com/questions/7197506/how-to-repair-comexception-error-80040154 – K3N

相關問題