none
Programmatically auto select an Excel table in Visual Basic in an Add-In - Exception from HRESULT: 0x800A03EC RRS feed

  • Question

  • I'm trying to mimic in VB the auto-selection of a whole table when clicking CRTL+* (asterisk).

    I have this code:

    Dim activeWorkbook As Excel.Workbook = CType(Application.ActiveWorkbook, Excel.Workbook)     

    Dim activeWorksheet As Excel.Worksheet = CType(Application.ActiveSheet, Excel.Worksheet)        

    Dim currentCell As Excel.Range = Me.Application.ActiveCell       

    Dim table_All As Excel.Range = activeWorksheet.Range(currentCell).CurrentRegion.Select()


    The last line throws this Exception:

    An exception of type 'System.Runtime.InteropServices.COMException' occurred in MorTest1.dll but was not handled in user code

    Additional information: Exception from HRESULT: 0x800A03EC

    What am I missing?

    Thanks!

    Wednesday, November 26, 2014 8:48 PM

Answers

  • Hi morsagmon,

    Please debug your code, make sure that the variables activeWorkbook,activeWorksheet,currentCell is not null when it goes to the line that throws the exception.

    This exception message usually cause by these problems:

    1. You use zero-based index for the Excel COM object, please make sure the index starts with 1 but not 0.

    2. You use the wrong version of Microsoft.Office.Interop.Excel to automate the Excel workbook, make sure the version is right. For example, the version is v15.0 for Excel2013, while it's v14.0 for Excel2010.

    3. You call the PIA on the server side, for example, in a asp.net web application.

    ...

    In your case, it most likely is the problem that you pass a null value the Range.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 28, 2014 6:32 AM
    Moderator
  • Hi.

    Thanks for the pointer!

    I started looking into it with your comments in mind, and I ended up with the following working solution:

    currentCell.CurrentRegion.Select()

    table_All = Me.Application.Selection

    Thanks!

    Tuesday, December 2, 2014 7:46 PM

All replies

  • Hi morsagmon,

    Please debug your code, make sure that the variables activeWorkbook,activeWorksheet,currentCell is not null when it goes to the line that throws the exception.

    This exception message usually cause by these problems:

    1. You use zero-based index for the Excel COM object, please make sure the index starts with 1 but not 0.

    2. You use the wrong version of Microsoft.Office.Interop.Excel to automate the Excel workbook, make sure the version is right. For example, the version is v15.0 for Excel2013, while it's v14.0 for Excel2010.

    3. You call the PIA on the server side, for example, in a asp.net web application.

    ...

    In your case, it most likely is the problem that you pass a null value the Range.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 28, 2014 6:32 AM
    Moderator
  • Hi.

    Thanks for the pointer!

    I started looking into it with your comments in mind, and I ended up with the following working solution:

    currentCell.CurrentRegion.Select()

    table_All = Me.Application.Selection

    Thanks!

    Tuesday, December 2, 2014 7:46 PM