Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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)

 

Here's 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!

  • Leaders
Posted

it should be something along these lines...

[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)

Posted

Hi

 

It doesn't 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 I've had to recompile it on a machine with 8.0 and Office 97 to support older users.

 

I can't open a workbook now - I've 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.

  • 1 year later...
Posted

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´t know why... but it works...

Just ignore the exception..

 

If anybody has a better solution for this issue ? please, let me know

 

Greetings from Colombia,

Arturo Cobos

arturo.cobos@gmail.com

Posted
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).
Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...