none
Word 2007, VSTO 2008, Exception when changing background color of a content control RRS feed

  • Question

  • Hello All,

    Here is my problem: I have a complex documents made out of rich text content controls (CC) organized in hierarchy (a big one contains others that contains some others,...). Besides that, I have tables contained also in rich text CC, and these tables can contain in their cells a rich text cc too. To summary, no content is out a rich text CC

    At the start up, I’m going through all these CC and set the background color base on a certain condition. Like that:

     

    CC.Range.Shading.BackgroundPatternColor = Microsoft.Office.Interop.Word.WdColor.wdColorGray20;

     

     When doing that, for some of the CC, an exception is raised:  This command is not available

    I made sure that none of the CC are locked (LockContent, and LockContentControl are set to false), even weirder if I select the problematic CC manually and set the color through the UI it works.

    Any suggestion will be welcomed.

    Thank you in advance,

     

    Wheedle79


    Thursday, March 24, 2011 3:08 PM

All replies

  • Hi Wheedle79,

    Thanks for posting in the MSDN Forum.

    Are you able to find out which RichTextContentControls occurred this exception?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Sunday, March 27, 2011 12:05 PM
    Moderator
  • Hello Tom,

    Thank you for your time.

    For some of them yes, when I get the exception I spoke before, I can find out thanks to the "catch" statement. The think now is that at some point the application doesn't answer at all (which wasn't like that before).

    But for those I could find out, they were at all level of the hierarchy of the document (as described in the first post).

    I thought that it could be the tables inside some controls, but the same thing happened after I deleted all the tables. Also I replicated the document in Word, and made a macro in VBA going through all the controls and setting the background color. The exact same thing happened.

    If you want I can try to make a dummy document that replicates the problem.

    Have a good day,

    Wheedle

    Monday, March 28, 2011 7:36 AM
  • Hi Wheedle,

    Would you please create a simple solution to reproduce your issue and share it on skydrive?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 29, 2011 10:06 AM
    Moderator