OpenClipboard Failed (Exception from HRESULT: 0x800401D0 (CLIPBRD_E_CANT_OPEN))'
I'm trying to put a text in an excel file (using Interop).
String EE = "Some random text here";
Thread thread1 = new Thread(() => Clipboard.SetText(EE));
thread1.SetApartmentState(ApartmentState.STA); //Set the thread to STA
thread1.Start();
thread1.Join(); //Wait for the thread to end
Microsoft.Office.Interop.Excel.Range CR1 = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[3, 1];
CR1.Select();
xlWorkSheet.Paste(CR1, false);
The error is coming from the second line. The problem here is that this error is not coming each time I run the code. If I click the button that runs the code, sometimes I get an error, and sometimes I don't, just like that. What could be the issue?
User contributions licensed under CC BY-SA 3.0