Exception from HRESULT: 0x800A03EC Error when using excel VSTO

ravi kumar 331 Reputation points
2021-01-17T10:56:59.893+00:00

i am creating excel VSTO , Where i need to filter the column "J" in my excel sheet which are greater than 0 and delete those rows and remove the filter again.The below code was working fine during debugging and testing , but when i published the same and installed , it is throwing me the below error:
I9XbM.png

this is the code::

using Microsoft.Office.Tools.Ribbon;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Excel;
using Microsoft.Office.Interop.Excel;
using System.Windows.Forms;

namespace CpCpk
{
    public partial class Ribbon1
    {
        private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
        {

        }

        private void button1_Click(object sender, RibbonControlEventArgs e)
        {
            try
            {
                var excelappp = Globals.ThisAddIn.Application;
                Excel.Worksheet Activeworksheet = Globals.ThisAddIn.Application.ActiveSheet;
                Activeworksheet.Range["A:S"].AutoFilter(Field: 10, Criteria1: ">0");
                excelappp.DisplayAlerts = false;
                Activeworksheet.Range["J2:J1000000"].SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeVisible).Delete();
                excelappp.DisplayAlerts = false;
                Activeworksheet.ShowAllData();
            }
            catch (Exception ex)
            {
                MessageBox.Show("the error is:" + ex);
            }

        }

please help me how to solve this:

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,309 questions
Office Development
Office Development
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Development: The process of researching, productizing, and refining new or existing technologies.
3,532 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Timon Yang-MSFT 9,576 Reputation points
    2021-01-19T05:33:07.837+00:00

    @ravi kumar
    Is the suffix of the current excel file "xls" or "xlsx"?
    If it is the former, the "J1000000" in the code may be the reason,
    The excel file in xls format has up to 65536 lines.