Home > Enterprise >  VSTO fatal error System.Runtime.InteropServices.COMException: 'Exception from HRESULT: 0x800A03
VSTO fatal error System.Runtime.InteropServices.COMException: 'Exception from HRESULT: 0x800A03

Time:05-08

I have used Imports Microsoft.Office.Interop and Reference of Microsoft excel is added to project/solution

Following are declaration

 Public xlsfilepath As String
 Public oxlsapp As New Excel.Application
 Public oxlsworkbook As Excel.Workbook
 Public oxlsworksheet As Excel.Worksheet
 Public oxlcellsrange As Excel.Range
 Dim xchar As String

Cell reading process from existing file

oxlcellsrange = oxlsworksheet.Cells(iRow, iCol)
MessageBox.Show(oxlsworksheet.Range(oxlcellsrange).Value)<----Here gives fatal error 

System.Runtime.InteropServices.COMException: 'Exception from HRESULT: 0x800A03EC'

Don't understand why?

Image is attached for that describes more.

Error message

CodePudding user response:

Reference of Microsoft excel is added to project/solution.

There's a confusing thing about Office Development. You need to reference the Private Interop Assemblies VSTO vs. Primary Interop Assemblies, what's the difference?

You might have mistakenly referenced the COM references and they're only supposed to be used in for UnitTesting Mocks of Office: https://stackoverflow.com/a/47256597/495455

CodePudding user response:

Excel COM references were set up correctly due to the fact that previous lines of code are working without errors. Moreover, that is a runtime error.

This is a widely-spread error when dealing with the Excel object model. You may find a similar posts like Exception from HRESULT: 0x800A03EC Error popular.

The Worksheet.Range property accepts a string that is a range reference when one argument is used. Either a string that is a range reference or a Range object when two arguments are used. For example:

Worksheets("Sheet1").Range("A1").Value = 3.14159
  • Related