Reputation: 50
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.
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)
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();
}
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.
Upvotes: 0
Views: 220
Reputation: 109
try to assign application object like below:-
Excel.Application oXL=Globals.ThisAddIn.Application;
Upvotes: 1