none
Accessing HighlightColorIndex in ContentControlAfterAdd event handler RRS feed

  • Question

  • I have C# based Word add-in that is handling the document's ContentControlAfterAdd event. In this handler, I am trying to access the HighlightColorIndex property of the content control's range. However, every time I try to do this I get the following exception:

    'control.Range.HighlightColorIndex' threw an exception of type 'System.Runtime.InteropServices.COMException'

    I can access this property outside of the ContentControlAfterAdd event handler.

    Code looks something like this:

    private void Document_ContentControlAfterAdd(OfficeWord.ContentControl control, bool undoRedo)
    
    {
    
     OfficeWord.WdColorIndex color = control.Range.HighlightColorIndex;
    
     // more code here
    
    }

    Any ideas as to why this is occurring? Any workaround?


    ThirtySix Software - http://www.thirtysix.net
    Wednesday, December 1, 2010 5:25 AM

Answers

  • Hi 36

    Basically, you can't affect document content while within this event. What you could do is create a Timer that calls code to execute after the event has finished...


    Cindy Meister, VSTO/Word MVP
    • Proposed as answer by Bessie Zhao Wednesday, December 8, 2010 9:34 AM
    • Marked as answer by Bessie Zhao Monday, December 13, 2010 11:10 AM
    Wednesday, December 1, 2010 11:09 AM
    Moderator