Search code examples
c#.netcomvstoexcel-addins

Random exception for my excel vsto add-in System.Runtime.InteropServices.COMException : 'Exception from HRESULT : 0x800A03EC'


I am developping an excel addin that monitor the clipboard of the user. You can start and stop the clipboard monitoring/recording with these two buttons.

My ribbon addin

This works really well so far, when a change in the clipboard is recorded, a form is opened. The clipboard content is pasted in a textbox (blue part of the screenshot)

enter image description here

When the user is done with his modification. He clicks the button in red to copy the text in the excel document he's working on.

Here is the code of the button.

private void ajouterExigenceBtn_Click(object sender, EventArgs e)
    {
        Excel.Application oXL;
        oXL = (Excel.Application)Marshal.GetActiveObject("Excel.Application");
        oXL.ActiveCell.Value = this.exigenceTextBox.Text;
        //currentSheet = (Microsoft.Office.Interop.Excel.Worksheet)Globals.ThisAddIn.Application.ActiveSheet;
        //currentSheet.Range["A1"].Value = this.exigenceTextBox.Text;
        this.Close();
        //this.Dispose();
    }

enter image description here

The problem is, that randomly, i get this exception

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

I really mean it, it's completely random, some time it works perfectly and the workbook is update as many times as i submit the form. Some times it only works once and then it doesn't anymore. I searched about this exception and i've tried everything but it just doesn't work. This is driving me nuts.

If anyone can help me...Thanks in advance.


Solution

  • try to assign application object like below:-

    Excel.Application oXL=Globals.ThisAddIn.Application;