none
Clear all formatting/styles in paragraph RRS feed

  • Question

  • Hi,

    what's the best way to clear all formatting/styles in a paragraph?

     

    I've already tried

    myParagraph.Range.set_Style(Word.WdBuiltinStyle.wdStyleNormal);

    But this only works if the corresponding paragraph uses only a single style, e.g. "Heading 1".

    If you have a paragraph which uses multiple styles, set_Style() seems to have no effect.

     

    Heading 1 paragraph.

    --set_Style()-->

    Heading 1 paragraph.

    (works!)

     

    Mixed style paragraph.

    --set_Style()-->

    Mixed style paragraph.

    (doesn't work!)




    • Edited by Lugaxx Tuesday, February 16, 2016 4:36 PM
    Tuesday, February 16, 2016 4:31 PM

Answers

  • Hi Lugaxx,

    >> what's the best way to clear all formatting/styles in a paragraph?

    I mentioned the way to clear the formatting in following code.

           private void ThisDocument_Startup(object sender, System.EventArgs e)
            {
                this.Select();
                ThisApplication.Selection.ClearFormatting();
            }

    It will also remove formatting of paragraph containing multiple style like you mentioned in your issue.

    Here my code select all the contents of the document and clear formatting but you can programmatically do the selection and then clear the formatting of selected content.

    # Selection.ClearFormatting
    https://msdn.microsoft.com/en-us/library/office/ff197496.aspx

    Regards,

    Edward

                           

    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.


    • Marked as answer by Lugaxx Wednesday, February 17, 2016 1:13 PM
    Wednesday, February 17, 2016 5:34 AM

All replies

  • Hi Lugaxx,

    >> what's the best way to clear all formatting/styles in a paragraph?

    I mentioned the way to clear the formatting in following code.

           private void ThisDocument_Startup(object sender, System.EventArgs e)
            {
                this.Select();
                ThisApplication.Selection.ClearFormatting();
            }

    It will also remove formatting of paragraph containing multiple style like you mentioned in your issue.

    Here my code select all the contents of the document and clear formatting but you can programmatically do the selection and then clear the formatting of selected content.

    # Selection.ClearFormatting
    https://msdn.microsoft.com/en-us/library/office/ff197496.aspx

    Regards,

    Edward

                           

    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.


    • Marked as answer by Lugaxx Wednesday, February 17, 2016 1:13 PM
    Wednesday, February 17, 2016 5:34 AM
  • Hi Edward,

    This works like a charm. Thank you.

    Cheers

    Wednesday, February 17, 2016 1:13 PM