none
How to resolve "Rich text controls cannot be applied here." exception? RRS feed

  • Question

  • Hi Everyone,

    I am creating an application where i am creating rich text content controls over certain amount of text. In case, when we have any overlapping content controls situations, it throws an exception "Rich text controls cannot be applied here.". I don't want to show this message to the user while applying content controls. I tried putting try catch block over the code but it still throwing this exception.

    Does any one knows, how to trap this exception?

    Thanks,


    Shahab Abbasi

    Wednesday, April 9, 2014 10:30 AM

Answers

  • Hi,

    To avoid this exception, we need to check and edit our codes to remove all the overlapping content controls situations instead of finding a method to bypass or turn off it.

    As we can see, overlapping content controls will cause contradictions. For example, if we successfully add the rich text content control in the sample which I post in my first reply, it will be hard to judge the last character "a" belongs to which content controls.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 10, 2014 6:41 AM
    Moderator
  • Hi Shahab Abbasi

    Why are you using content controls? Would using Bookmarks work for you, instead, if you need to overlap information?

    Word does have the Application.DisplayAlerts property that you can set to suppress some alerts, but it won't suppress all of them. You'd have to test whether it works for this particular one...


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, April 12, 2014 4:21 PM
    Moderator
  • In that case, about the only thing you can do is to check in your code whether the entire range is outside another content control or totally within another content control.

    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, April 24, 2014 4:50 PM
    Moderator

All replies

  • Hello Shahab,

    Did you try to debug? What line of code fires the exception?

    Wednesday, April 9, 2014 12:17 PM
  • Hi,

    According to your description, I assume you are developing a Word document-level add-in or an application-level add-in with VSTO.

    Do you mean “have any overlapping content controls situations” that adding a new rich text content control into a range containing a part of another existing rich text content control?

    If so, I’m afraid you cannot do that. I try to do that manually and get the same error below. So I think it is by design that we cannot “have any overlapping content controls situations”. And automation cannot avoid that.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 10, 2014 5:54 AM
    Moderator
  • Yes, i tried to debug that but exception is not getting handled by the try catch block.It always prompt the exception on the word screen.

    Here is the line that throws this exception:

    var contentControl = wdApplication.ActiveDocument.ContentControls.Add(Microsoft.Office.Interop.Word.WdContentControlType.wdContentControlRichText, ref obj_mySelectedRange);

    Thanks,


    Shahab Abbasi

    Thursday, April 10, 2014 6:24 AM
  • Thanks for the reply Luna Zhang,

    Yes, you are are absolutely pointing to the same situation. Is there any method defined, with the help of which we can turn off the exceptions which are basically raised by the word object model. Getting such kind of exceptions in front of users doesn't look good.

    Thanks,


    Shahab Abbasi

    Thursday, April 10, 2014 6:29 AM
  • Hi,

    To avoid this exception, we need to check and edit our codes to remove all the overlapping content controls situations instead of finding a method to bypass or turn off it.

    As we can see, overlapping content controls will cause contradictions. For example, if we successfully add the rich text content control in the sample which I post in my first reply, it will be hard to judge the last character "a" belongs to which content controls.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 10, 2014 6:41 AM
    Moderator
  • Hi Shahab Abbasi

    Why are you using content controls? Would using Bookmarks work for you, instead, if you need to overlap information?

    Word does have the Application.DisplayAlerts property that you can set to suppress some alerts, but it won't suppress all of them. You'd have to test whether it works for this particular one...


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, April 12, 2014 4:21 PM
    Moderator
  • Thanks for the rely Cindy,

    It's a requirement to use content controls. I will try to use the Application.DisplayAlerts and let you know...

    Thanks,


    Shahab Abbasi

    Friday, April 18, 2014 11:32 AM
  • Hi Cindy,

    I tried disabling alerts using Application.DisplayAlerts property, but word is still throwing the same exception. Don't know, how this can be handled.

    Thanks,


    Shahab Abbasi

    Thursday, April 24, 2014 7:27 AM
  • In that case, about the only thing you can do is to check in your code whether the entire range is outside another content control or totally within another content control.

    Cindy Meister, VSTO/Word MVP, my blog

    Thursday, April 24, 2014 4:50 PM
    Moderator