none
Formatting selected text inside content control RRS feed

  • Question

  • I noticed that if I run a VBA macro to format line 1 differently than line 2 inside a content control where the text is broken with a soft return (line feed) rather than a hard return, the whole paragraph is formatted EVEN if only the top line is highlighted.  This is not the case in regular text.  Is there a workaround for this?
    • Edited by orlandp Monday, February 27, 2012 12:02 AM
    Sunday, February 26, 2012 11:45 PM

Answers

  • Hi Orlandp,

    Thank you for posting.

    >>Whether I do it with code or MANUALLY SELECT text within the content control, it applies the character formatting to the entire content control.
    I think you added the Plain Text Content Control to the document which behaviors like what you described. You should add the Rich Text Content Control to achieve your goal. Please see the screen shot:

    Besides, please see this article:

    http://msdn.microsoft.com/en-us/library/bb157891.aspx

    which points out:

    A plain text control contains text. A plain text control cannot contain other items, such as tables, pictures, or other content controls. In addition, all of the text in a plain text control has the same formatting. For example, if you italicize one word of a sentence that is in a plain text control, all the text inside the control is italicized.

    Hope this can help you.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    • Edited by Bruce Song Friday, March 2, 2012 7:16 AM
    • Marked as answer by orlandp Monday, March 5, 2012 4:49 AM
    Friday, March 2, 2012 7:12 AM

All replies

  • Based on your description, I’d say that you are applying formatting to the whole range of the control, rather than to a specific sub-range. However, you will have to show us the code you are using.

    Stefan Blom, Microsoft Word MVP
    Monday, February 27, 2012 11:01 PM
  • The code finds a string in the content control.  I have stepped through the code and it selects the string text (not the complete content control) and applies character formatting (bold and underline).  Whether I do it with code or MANUALLY SELECT text within the content control, it applies the character formatting to the entire content control.  If I do the very same thing outside the content control on regular text (2 lines separated with a soft return), it does not change the entire paragraph, only the selected text.
    Tuesday, February 28, 2012 12:09 AM
  • Hi Orlandp,

    Thank you for posting.

    >>Whether I do it with code or MANUALLY SELECT text within the content control, it applies the character formatting to the entire content control.
    I think you added the Plain Text Content Control to the document which behaviors like what you described. You should add the Rich Text Content Control to achieve your goal. Please see the screen shot:

    Besides, please see this article:

    http://msdn.microsoft.com/en-us/library/bb157891.aspx

    which points out:

    A plain text control contains text. A plain text control cannot contain other items, such as tables, pictures, or other content controls. In addition, all of the text in a plain text control has the same formatting. For example, if you italicize one word of a sentence that is in a plain text control, all the text inside the control is italicized.

    Hope this can help you.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    • Edited by Bruce Song Friday, March 2, 2012 7:16 AM
    • Marked as answer by orlandp Monday, March 5, 2012 4:49 AM
    Friday, March 2, 2012 7:12 AM