I am working on a Word 2007 Document-Level Add-In, using a .dotm file. It's a document that is mostly controlled by buttons on the document pane, which are used to create and destroy certain parts of the document. Some of the things created are content controls.
One such button is a toggle, that needs to remove and re-add about 10 characters and a content control. My problem is that whenever I try to recreate the content control, Word throws a COMException with the message "Command Failed" and an error code of -2146824090 (or 0x800a1066).
Googling this error code suggests that this is a security-related exception related to using the
LevelControl.LockContentControl = false;
LevelControl = null; // probably not needed
DropDownListContentControl LevelControl = this.Controls.AddDropDownListContentControl(r, "SectionLevel");
The cause of my issue was a misplaced range object. I had unwittingly placed the range inside another content control, which still contained placeholder text. Unfortunately, the error message said nothing to this effect.
To determine whether you're making the same mistake, try calling
r.Select() at the end instead of whatever action may be causing this exception, and see where the cursor is placed. Be sure that the document is not limited to editing in fields when you do this (
Review>Protect Document>Restrict Editing and Formatting), otherwise it may automatically move to the beginning of the document, or into a content control, before you can see it.