New Excel.Workbook error

Liz

New member
Joined
Mar 17, 2004
Messages
2
In coverting my VB6 code to .NET I get an run time error when declaring a new Excel.Workbook:

Dim oExcel As New Excel.Application
Dim oWorkbook As New Excel.Workbook <- error is here
Dim oWorksheet As New Excel.Worksheet
oWorkbook = oExcel.Workbooks.Open(FullPath)

Heres the error: An unhandled exception of type System.Runtime.InteropServices.COMException occurred in app.exe
Additional information: COM object with CLSID {00020819-0000-0000-C000-000000000046} is either not valid or not registered.

However, I have verified that the Microsoft Excel 10.0 Object Library is registered (I am using Excel 2002).

Any help would be greatly appreciated!
 
it should be something along these lines...
Code:
[COLOR=Blue]Dim[/COLOR] oExcel [COLOR=Blue]As New[/COLOR] Excel.Application

[COLOR=Blue]Dim[/COLOR] oWorkbook [COLOR=Blue]As[/COLOR] Excel.Workbook = oExcel.Workbooks.Open(FullPath)
 
Hi

It doesnt work for me - I have the same problem but with the 8.0 code library.

My app worked with Excel 10.0 and 2002, but Ive had to recompile it on a machine with 8.0 and Office 97 to support older users.

I cant open a workbook now - Ive tried yours and various other syntax variations:

Dim excelApp As New Excel.Application
Dim wb As Excel.Workbook

This method used to work with 10.0 but now errors:
wb = excelApp.Workbooks.Open(sourcePath, 0, False, 5, "", "", True, Excel.XlPlatform.xlWindows, "\t", True, False, 0, True)

These methods all error as well:

wb = excelApp.Workbooks.Open(sourcePath)

wb = excelApp.Workbooks.Open(sourcePath, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)

wb = excelApp.Workbooks.Open(sourcePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing)

Dim wb As Excel.Workbook = excelApp.Workbooks.Open(sourcePath)

Dim wbs As Workbooks
wbs = excelApp.Workbooks
wb = wbs.Open(Filename:=sourcePath)


The error I get is on the .Open method:

System.Runtime.InteropServices.COMException (0x80010105): The server threw an exception.
at Excel.Workbooks.Open(String Filename, Object UpdateLinks, Object ReadOnly, Object Format, Object Password, Object WriteResPassword, Object IgnoreReadOnlyRecommended, Object Origin, Object Delimiter, Object Editable, Object Notify, Object Converter, Object AddToMru)

Any ideas? This has really stumped me. I think the problem is unique to the 8.0 library.
 
OLB 8.0 ignore the exception

I have the Same Problem with olb 8.0

hmm.

but look at this . I am try this right now. the thing aparently works :

excelapp = new excel.application

try

wkbobj = excelapp.workbooks.Open(str_File_name)
Here fires a exception
catch ex as exception
end try


try

wkbobj = excelapp.workbooks(0)
Here fires a exception
catch ex as exception
end try

wksobj = wkbobj.worksheets(1)


(?) I don
 
For older versions of Office, late binding seems to be more reliable. Remove the reference to the Excel library; declare the Excel application / workbook / worksheet etc As Object; and use CreateObject to create the Application object (instead of using the New keyword).
 
Back
Top