Word 2010 - Is There A Way To Replace Styles In Multiple Documents?

I have a number of documents that have been formatted with a set of styles.  The styles have changed format, and now I have to update many documents to the new style set.

 

I know this can be done by using the style organizer; however this is only one document at a time.

 

Is there a way to create a style master, and use it to update the styles in multiple documents?    Ideally, this would use a master document as the source, and modify all files within a specified directory.

 

(Note: the style names did not change, only the paragraph format within each style.)

Yes, with vba (macros).

See A Global StyleSheet in Microsoft Word?

You could have a macro that is set with a keyboard shortcut and called upon demand, otherwise you could have an AutoOpen macro that would run each time any document is opened and run it then. You might want to have it triggered by the Document_Open event rather than be in an AutoOpen macro. See Run a macro automatically when a document is created, opened or closed.
Volunteering to "pay forward" the help I've received in the Microsoft user community.

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

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.

You might also consider this:

If the normal paragraph style is changing or even if you aren't using normal in your documents but the regular text paragraph style (Body Text, para, etc.) is changing, you should create a Word style set (or Quick Style Set). 
Make a style set by saving styles to the Styles Gallery (& deleting those you do not want from the gallery).  Be sure to include normal in the styles gallery and be sure that the settings in normal are the same as those in the defaults in the document you are creating the styles gallery in. When you save the style set, Word creates a mini template that contains the styles gallery and the defaults from the document you created the style set in. When you apply a style set in a document , the styles in the document will take on the settings from the style set and if a style  in the style set was not already  in the document, and the defaults will be brought into to the new document

I use style sets often both to add new styles and to change the settings of existing styles.  I haven't created a macro to change style sets.  So what follows is a suggestion of something to try:

W2010 VBA has the ability to apply quick style sets (see this Office Dev Center page), for example,

ActiveDocument.ApplyQuickStyleSet2 "Elegant"

and finding a VBA code "wrapper" that will repeat that command in every  file in a folder, shouldn't be too hard. 

I like style sets for this because you fix the problem of mismatched normal and defaults in your documents--and avoid the problems it can cause--while changing your styles. 



Pamelia Caswell

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.

I'd be inclined to do this via a macro like:

 

Sub UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String
Dim SBar As Boolean, wdDoc As Document
SBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, _
    AddToRecentFiles:=False, Visible:=False)
  StatusBar = "Processing: " & strFile
  With wdDoc
    If .AttachedTemplate.Name = "Normal.dot" Then
      .UpdateStylesOnOpen = True
      .UpdateStylesOnOpen = False
    End If
    .Close SaveChanges:=True
  End With
  strFile = Dir()
Wend
Set wdDoc = Nothing
Application.DisplayStatusBar = SBar
Application.ScreenUpdating = True
End Sub

 

Function GetFolder() As String
Dim oFolder As Object
GetFolder = ""
Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
Set oFolder = Nothing
End Function

 

What the above macro does is to open a browser so you can select the folder of interest, then goes through all documents in that folder, setting the 'UpdateStylesOnOpen' property 'on' for any that are based on the 'Normal' template. From now on, any such document would ordinarily be forced to comply with the Style definitions in the underlying template. Since you may not want that, it then re-sets the 'UpdateStylesOnOpen' property to 'off' before saving the document.

 

Change the "Normal.dot" template name to match yours.

 

For installation & usage instructions, see: http://www.gmayor.com/installing_macro.htm

 

Hint: Don't add the macro to a document saved in your 'folder of interest'.

Cheers
Paul Edstein
(Fmr MS MVP - Word)

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.

Hi,

How can i run a single Macro (as shown below) in multiple files in a folder.

For eg, if i have 100 doc/docx files how can i run a single macro in all the 100 files?

MACRO -

Sub footnotearangectrlnumlock1()
'
' footnotearangectrlnumlock1 Macro
'
'

Selection.WholeStory
    Selection.Font.Name = "Book Antiqua"
    Selection.Font.Size = 8
    With Selection.ParagraphFormat
        .SpaceBefore = 3
        .SpaceBeforeAuto = False
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphJustify
        .KeepWithNext = False
        .KeepTogether = False
        .PageBreakBefore = False
        .NoLineNumber = False
        .Hyphenation = True
        .OutlineLevel = wdOutlineLevelBodyText
        .LineUnitBefore = 0
        .MirrorIndents = False
    End With
    With Selection.ParagraphFormat
        .SpaceBeforeAuto = False
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphJustify
        .OutlineLevel = wdOutlineLevelBodyText
        .MirrorIndents = False
    End With
    With Selection.ParagraphFormat
        .LeftIndent = CentimetersToPoints(0.5)
        .RightIndent = CentimetersToPoints(0)
        .SpaceBefore = 3
        .SpaceBeforeAuto = False
        .SpaceAfter = 3
        .SpaceAfterAuto = False
        .LineSpacingRule = wdLineSpaceSingle
        .Alignment = wdAlignParagraphJustify
        .FirstLineIndent = CentimetersToPoints(-0.5)
        .OutlineLevel = wdOutlineLevelBodyText
        .CharacterUnitLeftIndent = 0
        .CharacterUnitRightIndent = 0
        .CharacterUnitFirstLineIndent = 0
        .LineUnitBefore = 0
        .LineUnitAfter = 0
        .MirrorIndents = False
    End With
End Sub

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.

The code I posted can be repurposed by replacing:

    If .AttachedTemplate.Name = "Normal.dot" Then
      .UpdateStylesOnOpen = True
      .UpdateStylesOnOpen = False
    End If

with the appropriate code.

That said, your code appears to be going about its task entirely the wrong way. For starters, it seems to be aimed a working with footnotes, but relies on selection something first. How do you propose to select the entire footnote range in each document? What about if the document has no footnotes? The proper way to modify a document's footnotes is to modify the footnote text Style. That way (a) it doesn't even matter whether the document has any footnotes; (b) nothing needs to be selected; and (c) it's far faster.

Cheers
Paul Edstein
(Fmr MS MVP - Word)

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.

What you are doing is what is called direct formatting rather than changing styles. This is not the way to use Word. It is far more work for you; it makes Word work harder as well; you can easily miss something.

Use the code that Macropod provided, assuming that you set the formatting you want in your normal template.

Understanding Styles in Microsoft Word

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

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

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 October 5, 2021 Views 2,452 Applies to: