QueryInterface for interface Microsoft.Office.Interop.Excel._Application

ashutosh9910

Active member
Joined
May 13, 2005
Messages
44
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
 
This is what I use to access an excel document using a winform. Hopefully it will give you some ideas.

[VB]
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
[/VB]

Hope this helps
 
SonicBoomAu said:
This is what I use to access an excel document using a winform. Hopefully it will give you some ideas.

[VB]
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
[/VB]

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
Code:
objBook = objBooks.Open(strExcelFile2Load)
 
This code doesnt 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?
 
SonicBoomAu said:
This code doesnt 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

Code:
[COLOR=Red]objBook = objBooks.Open(strExcelFile2Load)[/COLOR]
 
[VB]
dim strExcelFile2Load as string
strExcelFile2Load = "C:\Inetpub\wwwroot\ExcelWriter\Templets\BenchmarkData_Histogram.xls"

[/VB]

I take it that you have defined strExcelFile2Load somewhere?
Have you added a reference to Excel?
 
SonicBoomAu said:
[VB]
dim strExcelFile2Load as string
strExcelFile2Load = "C:\Inetpub\wwwroot\ExcelWriter\Templets\BenchmarkData_Histogram.xls"

[/VB]

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. .............
 
Back
Top