Sometimes when your are Automating Excel, you may see an exception similar to the following:
System.Runtime.InteropServices.COMException was unhandled
Message="Exception from HRESULT: 0x800A03EC"
This may seem random and may not seem to occur on your system. Well, this is a fairly common issue I have experienced in the field. And, there is not a lot of good information about it on the web. Until now…
The problem occurs because Excel is in edit mode. The user has a cell selected and text currently being typed into it, but they have not yet clicked out of the cell.
Note, when this happens Excel grays out the Ribbon items and most options are unavailable.
Well, there really is not an easy way to determine this state for Excel, so the following code can be used to determine if Excel is in Edit Mode and also to get it out of Edit mode. The only call you need to make is exitEditMode(). If Excel is OK, nothing happens; however, if it is in edit mode, it pops it out so your automation code can continue.