Word 2004 Tip: Adding an ‘Update Styles from Template’ command
Posted by Pierre Igot in: MacintoshJune 18th, 2004 • 12:33 am
If you use document templates in Word on a regular basis, you are probably faced with the following situation occasionally: You open a old document originally based on Template X and realize that its style sheet is missing a number of styles that you added to Template X later on.
So you want to update the style sheet in the old document to make it match the updated style sheet in Template X.
The problem is that there is no easy way to do this in Word’s interface. You can use the “Organizer” command to open a Font/DA Mover type of dialog box that lets you copy styles from one file to another, but it’s rather cumbersome.
A faster way is to re-attach Template X to the document. You can do that by using the “Templates and Add-ins” dialog box works is rather impenetrable and even that is not exactly convenient.
” command in the “ ” menu. But the way the “Fortunately, there is a solution, with the help of VisualBasic. You just need the following macro:
Sub UpdateStylesFromTemplate() With ActiveDocument .UpdateStyles End With End Sub
Add this macro to one of your customized Word menus or toolbars, and you’ll have a command that does exactly what it says: it updates the style sheet of the currently active document based on the style sheet of the template that the document is based on.
Of course, this assumes that the template still exists in its original location. Otherwise the command will not work. Also, you should note that this command can be destructive, because it effectively replaces the styles in your document’s style sheet with the ones from the template if they have the same name. So if you made any changes to the styles after creating the document from the template originally, these changes will be lost.
It should also be noted that Word has an option to “Automatically update document styles” in the “Templates and Add-ins” dialog box. What this option does is that it automatically updates the styles of the document based on the styles in the template every time you open the document. I find it quite dangerous, and I never turn it on for any document. But you should know that it exists, if you never make any changes to your template-defined styles in a document after you created it. (I sometimes do, for specific documents, so I don’t want Word to override these changes the next time it opens the documents in question.)
June 18th, 2004 at Jun 18, 04 | 3:54 pm
God, styles in Word are so messed up. They tell you to use them, and then pull all kinds of crazy crap with them.
I had to whip up a system at work a couple of years back that attached different templates to a document depending on a selection made from a toolbar dropdown menu. By far the biggest headache was updating the styles properly whenever the template was switched. .UpdateStyles didn’t quite cut it like it should have. I ended up having to use a macro to copy each style I wanted over into the new doc, which of course makes it difficult to add new styles in the future without having to change my code.
And I turn off that “Automatically update document styles” nonsense too. One forgotten style change and you’re screwed.
Eh, I’m just venting now, but it’s nice to see that I’m not alone with my styles headaches.
June 18th, 2004 at Jun 18, 04 | 11:47 pm
I am afraid I know exactly what you mean. :-/ And there’s nothing worse than having to write a lousy ad-hoc VisualBasic macro because the default macro command that seems to be designed for what you want to do doesn’t work as expected. I’ve been through that myself. And I can’t say I enjoy programming in VB!
Do you have any idea why .UpdateStyles didn’t work in your case? I was surprised to find that it worked myself, especially in light of the fact that it was not what the macro recorder had recorded when I had tried to do the action manually.
June 19th, 2004 at Jun 19, 04 | 11:39 am
Thanks for the added information… It might have had to do with the fact that Heading and TOC styles are “special” styles in Word that tend to behave differently from “pure” user-created styles. Much in the same way that I no longer attempt to customize the Word toolbars and just hide them and create my own, I now stay away from using Word’s default styles and use my own heading styles instead. Of course, for automatic TOCs, it’s not so easy…
I can easily imagine that Word would screw up the numbering when transferring styles from document/template to document. Heck, it even manages to screw up the numbering when you don’t move styles around. Sometimes it looks like simply staring at your screen in the wrong way is enough for Word to start screwing up on you.
Sigh.
June 19th, 2004 at Jun 19, 04 | 8:56 am
Without going back and looking at my comments in the VBA code and keeping in mind that this was 2+ years ago, I seem to recall that the problem was mostly with Heading and TOC styles and the numbering associated with them. That was, in fact, the main point of the whole system: to allow different groups within the company to use the same documents but each have their own TOC and numbering styles that they could change on the fly. The “on the fly” part was the killer to implement.
IIRC, I did use .UpdateStyles but then also used a VBA command (I forget which one) to copy each style one-by-one. That was the only way I could get all of the style info to come over.