locked
CopyStylesFromTemplate Method Problem in Word 2013 RRS feed

  • Question

  • Hi,

    I am using CopyStylesFromTemplate  to update the styles in a new document that was created from the template.

    If I use the following when I start running the macros, when I open the document I see that the definition of the some of the stykles is not correct (for example, indentation of lists):

    With ActiveDocument
            .CopyStylesFromTemplate ActiveDocument.AttachedTemplate.FullName
            .UpdateStyles
    End With

    If I run the exact same code just before the macros end, the styles in the new document are updated correctly.

    The problem is that some of my macros check for indentation issues and when the styles are not correct then the result isn't either.

    Any idea how to make it work?

    Thanks,

    Rocky

    Monday, December 21, 2015 7:32 AM

Answers

  • Hi Rock_l,

    The both Document.CopyStylesFromTemplate and Document.UpdateStyles are used copy the styles from the template.

    >>If I use the following when I start running the macros, when I open the document I see that the definition of the some of the stykles is not correct (for example, indentation of lists):<<

    Please ensure that there are no duplicate style in active document and its template.

    Based on my understanding, if there are a style name Style1 exits in both document and templates and the indentation of two style is different. After we run the code, the style from template would replace the one in active document.

    If you still have the problem, would you minding provide the detail steps to help us reproduce this issue so that we can provide more helpful suggestions?

    Regards & Fei


    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.

    Friday, December 25, 2015 6:08 AM

All replies

  • Hi Rocky

    Word's numbering feature was changed substantially since the methods to copy and update styles were built into Word. These simply do not reliably recognize when styles are linked to numbering and thus do not copy the information associated with the numbering across correctly.

    If the later execution appears to be reliable then try finding out what part of the macros is enabling the update to occur correctly and let that run "empty" (no visible result), then execute the style updates and then run the complete macro with visible result.


    Cindy Meister, Office Developer/Word MVP, <a href="http://blogs.msmvps.com/wordmeister"> my blog</a>

    Monday, December 21, 2015 5:18 PM
  • I am trying, but it is a long macro with many Subs and functions. Was hoping for some known issues...
    Tuesday, December 22, 2015 11:19 AM
  • Hi Rock_l,

    The both Document.CopyStylesFromTemplate and Document.UpdateStyles are used copy the styles from the template.

    >>If I use the following when I start running the macros, when I open the document I see that the definition of the some of the stykles is not correct (for example, indentation of lists):<<

    Please ensure that there are no duplicate style in active document and its template.

    Based on my understanding, if there are a style name Style1 exits in both document and templates and the indentation of two style is different. After we run the code, the style from template would replace the one in active document.

    If you still have the problem, would you minding provide the detail steps to help us reproduce this issue so that we can provide more helpful suggestions?

    Regards & Fei


    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.

    Friday, December 25, 2015 6:08 AM