I am trying to generate a Word 2007 from a C# Add-in using Visual Studio 2008 Beta 2. The code creates the document from a pre-defined template.
I need to do some manipulation to the document to inject data from our application in placeholders specified by the user.
The document essentially contains a series of tables that I need to clear down and rebuild. I use Group Content Controls to lock the tables so that the user can't delete them unintentionally.
Anyway, I am experiencing a couple of different COM Exceptions from Word and I can't determine that the cause of the problems are to implement a reliable fix.
1. If I try to unlock a content control group with
2. Since the ungroup() method failed with the above bizarre exception, I tried to remove it with the delete() method instead. The
My initial thought was to check if something is selected and collapse the selection. However, querying the following in Visual Studio reveals:
objWord.Selection.Range.Start = 0 and
objWord.Selection.Range.End = 1
The range of the group I am trying to unlock is from the range 1003 to 1220, so I don’t understand how there could be an overlap as the current selection is nowhere near my content control.
Can anyone explain why the above errors are happening and advise on how to resolve the situation. The first error looks like a bug in Word 2007, but the second is bizarre - what is the selection that word thinks is locked for editing, and how do I unlock it to make my changes?Thanks in advance.
Peter
Replies
Know the answer? Post it — somebody with the same question will find it here.