0

I am new to develop VSTO add-in. Following the second VSTO code example of the walkthrough How to: Programmatically list all worksheets in a workbook, the VSTO add-in is no problem in Excel 2021 but throwing an Exception System.Runtime.InteropServices.COMException: 'Exception from HRESULT: 0x800A03EC' in Excel 2013 at line Excel.Range rng = this.Application.get_Range("A1"); .

I installed both 2013 and 2021 versions on Windows11 and I use VS2021 to develop. Thanks for answers.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Li-Guangda
  • 341
  • 1
  • 4
  • 14

1 Answers1

0

The Application.Range property has the following description in MSDN:

When used without an object qualifier, this property is a shortcut for ActiveSheet.Range (it returns a range from the active sheet; if the active sheet isn't a worksheet, the property fails).

So, I'd suggest getting an instance of the Worksheet class and calling this property against it.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • I think it doesn't answer my question ... – Li-Guangda Jan 01 '22 at 12:45
  • Have you tried getting a Worksheet instance and then call for a range? Does it work correctly? – Eugene Astafiev Jan 01 '22 at 12:54
  • I want to figure out why the add-in work in Excel 2021 but not in Excel 2013. I think your answer does't explain it. – Li-Guangda Jan 01 '22 at 13:05
  • There are many possible causes. See [Exception from HRESULT: 0x800A03EC Error](https://stackoverflow.com/questions/12714626/exception-from-hresult-0x800a03ec-error) for more information. – Eugene Astafiev Jan 01 '22 at 15:26
  • A brief search on this suggests differences in the .NET framework between versions. If you are using the up to date visual studio it may be that your current version of .NET is not compatible with Excel 2013. This is just speculation as I haven’t done much with VSTO. From the example you are following it looks like the suspect line is the first that actually tries to use the Excel Application object. This may indicate that the object hasn’t been created successfully. So as @EugeneAstafiev says, try a different function and see if that works. – DS_London Jan 01 '22 at 16:18