Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Dec 2011
    Posts
    33
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Copy styles from one template to multiple files (Word 2010)

    Hi folks,

    I have a custom template (.dotm) with about 10 styles in it. I want to copy those styles into about 100 documents based on Normal.dot. What's the easiest way to do this without opening each file manually and going through the Organizer.

    Thanks,

    Beej

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,055
    Thanks
    2
    Thanked 417 Times in 346 Posts
    You could create a document with ten empty paragraphs, one formatted in each of the Styles. Then use a macro to loop through the 100 other files, copying the ten empty paragraphs in to them, then deleting them. That will add the Styles to the target documents. For example:
    Code:
    Sub UpdateDocumentStyles()
    Application.ScreenUpdating = False
    Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document
    Dim RngSrc As Range, RngTgt As Range
    With ActiveDocument
      strDocNm = .FullName
      Set RngSrc = .Range
    End With
    strFolder = GetFolder
    If strFolder = "" Then Exit Sub
    strFile = Dir(strFolder & "\*.doc", vbNormal)
    While strFile <> ""
      If strFolder & "\" & strFile <> strDocNm Then
        Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
        With wdDoc
          With .Range
            .InsertAfter vbCr
            Set RngTgt = .Characters.Last
            With RngTgt
              .FormattedText = RngSrc.FormattedText
              .Delete
            End With
            .Characters.Last.Delete
          End With
          .Close SaveChanges:=True
        End With
      End If
      strFile = Dir()
    Wend
    Set wdDoc = Nothing
    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
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. The Following User Says Thank You to macropod For This Useful Post:

    ItsjustBeej (2016-02-16)

  4. #3
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts
    An intermediate step would be loading your template as an Add-In and having a macro in the template that copies the styles to the active document.
    See a Global StyleSheet for Word.
    Charles Kyle Kenyon
    Madison, Wisconsin

  5. The Following User Says Thank You to Charles Kenyon For This Useful Post:

    ItsjustBeej (2016-02-23)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •