ashutosh9910 Posted September 5, 2006 Posted September 5, 2006 Hi all, I am trying to use Office Automation in my ASP.NET application using the Office XP PIAs. This is the exception I gt when I try to create a workbook using the following code: Try Dim excel As Application = New Application Dim wb As Workbook Dim missing wb = excel.Workbooks.Open("C:\Inetpub\wwwroot\ExcelWriter\Templets\BenchmarkData_Histogram.xls") excel.Visible = True wb.Activate() Catch ex As Exception Dim strError As String = ex.Message End Try It raises an exception on the line where I open the workbook: wb = excel.Workbooks.Open("C:\Inetpub\wwwroot\ExcelWriter\Templets\BenchmarkData_Histogram.xls") Kindly help. THanks Ashutosh Quote http://vyasashutosh.blogspot.com
SonicBoomAu Posted September 6, 2006 Posted September 6, 2006 This is what I use to access an excel document using a winform. Hopefully it will give you some ideas. Dim objApp As Excel.Application Dim objBook As Excel._Workbook Dim objBooks As Excel.Workbooks Dim objSheets As Excel.Sheets Dim objSheet As Excel._Worksheet Dim range As Excel.Range Try objApp = New Excel.Application objBooks = objApp.Workbooks objBook = objBooks.Open(strExcelFile2Load) objSheets = objBook.Worksheets objSheet = CType(objSheets(1), Excel.Worksheet) Catch ex As Exception MessageBox.Show(ex.Message) End Try Hope this helps Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
ashutosh9910 Posted September 7, 2006 Author Posted September 7, 2006 This is what I use to access an excel document using a winform. Hopefully it will give you some ideas. Dim objApp As Excel.Application Dim objBook As Excel._Workbook Dim objBooks As Excel.Workbooks Dim objSheets As Excel.Sheets Dim objSheet As Excel._Worksheet Dim range As Excel.Range Try objApp = New Excel.Application objBooks = objApp.Workbooks objBook = objBooks.Open(strExcelFile2Load) objSheets = objBook.Worksheets objSheet = CType(objSheets(1), Excel.Worksheet) Catch ex As Exception MessageBox.Show(ex.Message) End Try Hope this helps I guess the above creates an instance of Excel Application which obviously I do not want to use. Instead I am using Office XP PIAs and so if you look at my code its quite similiar to urs. So I guess the line that raises the error is objBook = objBooks.Open(strExcelFile2Load) Quote http://vyasashutosh.blogspot.com
SonicBoomAu Posted September 7, 2006 Posted September 7, 2006 This code doesn't raise any errors. The strExcelFile2Load is defined earlier, this is the location of the file I wish to access. Did you try using the above code and see if it opened the excel document for you? Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
ashutosh9910 Posted September 12, 2006 Author Posted September 12, 2006 This code doesn't raise any errors. The strExcelFile2Load is defined earlier, this is the location of the file I wish to access. Did you try using the above code and see if it opened the excel document for you? Object Reference Not set to an instance of an object on line [color=Red]objBook = objBooks.Open(strExcelFile2Load)[/color] Quote http://vyasashutosh.blogspot.com
SonicBoomAu Posted September 14, 2006 Posted September 14, 2006 dim strExcelFile2Load as string strExcelFile2Load = "C:\Inetpub\wwwroot\ExcelWriter\Templets\BenchmarkData_Histogram.xls" I take it that you have defined strExcelFile2Load somewhere? Have you added a reference to Excel? Quote Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -- Rick Cook, The Wizardry Compiled
ashutosh9910 Posted September 15, 2006 Author Posted September 15, 2006 dim strExcelFile2Load as string strExcelFile2Load = "C:\Inetpub\wwwroot\ExcelWriter\Templets\BenchmarkData_Histogram.xls" I take it that you have defined strExcelFile2Load somewhere? Have you added a reference to Excel? strExcelFile2Load has been defined. Not a problem there is a reference to Excel. ............. Quote http://vyasashutosh.blogspot.com
Recommended Posts