0

I got a null exception error in my code and I cannot understand why.

I have an excel file named 'FilterXpath' added to my project in 'Resources'. I have the code the below:

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.
Edward
  • 3,292
  • 1
  • 27
  • 38
user1724956
  • 75
  • 3
  • 3
  • 7

1 Answers1

1

declare them as New instance

Dim FilterXpath As New Microsoft.Office.Interop.Excel.Application 
Dim w As New Microsoft.Office.Interop.Excel.worksheet Dim sheet As Worksheet
John Woo
  • 258,903
  • 69
  • 498
  • 492
  • thanks for the advise.but still i get COM component retrieving error 80040154 in the line 'Dim FilterXpath As New Microsoft.Office.Interop.Excel.Application ' – user1724956 Oct 20 '12 at 17:03
  • For this error, check this thread http://stackoverflow.com/questions/7197506/how-to-repair-comexception-error-80040154 –  Oct 21 '12 at 14:55