Macro to copy styles from one template to another

I am wondering if someone can assist with a macro that will copy the Word Styles contained in one template to be copied to another template.

I am trying to get some consistency at my workplace and have created a custom addin template that has a toolbar that allows a user to click on an icon and it applies a particular style so that the user can do headings etc that are formatted.

What I would also like to do if it is possible is to be able to allow the user if they open a document that doesn't contain the styles linked to the custom ribbon allow the user to click on an icon if they want to import those styles into the document.

Any ideas how I can do this?

STC

Answer
Answer

Hi Charles and Jay,

Thanks for referencing me! :-)

One remark: it's

ActiveDocument.CopyStylesFromTemplate NormalTemplate.FullName

with a space instead of a dot between CopyStylesFromTemplate and NormalTemplate.

Thank you Hans.

I fixed it on my web page. It is now showing as:

ActiveDocument.CopyStylesFromTemplate (NormalTemplate.FullName)


I've tested this and it is what is shown on the support page.

I expect that the space acts the same.

(I also change it in Jay's response marked as the Answer since many people do not bother to read a full thread when there is an answer marked.)

Volunteering to "pay forward" to return help I've received in the Microsoft user community.]


Charles Kenyon
Sun Prairie, Wisconsin
wordfaq[at]addbalance[dot]com

Legal website: http://addbalance.com

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Answer
Answer

Visit http://www.addbalance.com/usersguide/styles.htm#Troubleshooting and scroll down to the end of that subsection to the  two macros. The second macro is

Sub CopyNormalStyles()
   ' Copies styles from normal template
   ' 2019-12-01   Hans Vogelar
   ActiveDocument.CopyStylesFromTemplate (NormalTemplate.FullName)
End Sub

To copy the styles from the add-in template to the current document, replace the statement in the macro above with one containing the path and name of the template, like this:

    ActiveDocument.CopyStylesFromTemplate Environ("APPDATA") & _

         "\Microsoft\Word\STARTUP\MyAdd-In.dotm"


Copying all the styles in bulk like this is much more efficient that copying one style at a time.

_____________________________
https://jay-freedman.info

2 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated April 12, 2020 Views 103 Applies to: