richard smith

richard smith

  • 1.4k
  • 285
  • 160.8k

Weird Debug Error

Mar 2 2013 11:50 AM
I keep getting a NullReferenceException was unhandled error in my code.  The strange thing to me, is I am checking if the actual workbook name exists before I attempt to open it, and it passes the check of ifexists (as well as I have navigated to the location and physically checked it and opened it) Below is my code, can someone see what is throwing the error?
What's even more peculiar to me is I run the same line of code in a different location and it passes through the code like a hot knife on butter!?!?!?!

//Declaring Variables
Excel._Workbook oWB;
Excel.Application oXL;

//Checking if file exists
if (File.Exists(filePath + workbookName + ".xls")) //code makes it through here FINE!!!!

oWB.oXL.Workbooks.Open(filePath + workbookName + ".xls"); //This line throws the reference exception. 
{
//run code once workbook is open
}

Answers (1)