none
CopyStylesFromTemplate Method Problem in Word 2013 RRS feed

  • Question

  • When I use the CopyStylesFromTemplate method in Word 2010 I get all of the styles intact. I have styles Heading 1 through Heading 9 and all is well. When I use the same code in 2013 the names of the styles are changed to Heading x,hx where x is the level number and the style for Heading 1,h1 is wrong but the styles for 2-9 are correct.

    This same piece of code produces the results above:

    myDoc.CopyStylesFromTemplate(myTemplate)

    I would greatly appreciate any insights or help into the issue.

    Thanks in advance.

    Tuesday, July 15, 2014 8:39 PM

Answers

  • I've performed a quick test in Word 2013 and cannot reproduce the problem. I saved a document as a template file (*.dotx), changed the Heading styles 1 through 3 (different text color), then used the CopyStylesFromTemplate method. I don't see any additional aliases and the styles came across correctly.

    FWIW Word will use the h1, h2, etc. aliases for the Heading styles if the document has been saved as a web page or something similar, if that rings any bells with you...


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, July 18, 2014 6:01 PM
    Moderator

All replies

  • Hi,

    Welcome to MSDN forum.

    According to Document.CopyStylesFromTemplate Method (Word):

    When styles are copied from a template to a document, like-named styles in the document are redefined to match the style descriptions in the template. Unique styles from the template are copied to the document. Unique styles in the document remain intact.

    Does h1 exist in current document after executing the code?

    In addition, would you mind uploading the template and sharing the code for us to reproduce this issue?


    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, July 17, 2014 3:01 AM
    Moderator
  • I've performed a quick test in Word 2013 and cannot reproduce the problem. I saved a document as a template file (*.dotx), changed the Heading styles 1 through 3 (different text color), then used the CopyStylesFromTemplate method. I don't see any additional aliases and the styles came across correctly.

    FWIW Word will use the h1, h2, etc. aliases for the Heading styles if the document has been saved as a web page or something similar, if that rings any bells with you...


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, July 18, 2014 6:01 PM
    Moderator