• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

5. Templates and Outlines > 48. Attach the Same Template to Multiple Files

Attach the Same Template to Multiple Files

Use a macro to update or change the template for all the files in a folder.

When documents are passed around among reviewers or contributors, you’ll often want to reattach the correct template when you get the files back. Doing that for more than a few files can be a real chore, though. This hack shows how to attach the template used by the current document to all the documents in the same folder as the current document.

The Code

Place this macro in the template of your choice [Hack #50] and either run it from the ToolsMacroMacros dialog or put a button for it on a menu or toolbar [Hack #1] :

Sub DocTemplateToAllFilesInFolder( )
Dim i As Integer
Dim doc As Document
Dim sFolder As String
Dim oTemplate As Template
Dim sFileFullName As String
Dim sFileName As String

sFolder = ActiveDocument.Path
If Len(sFolder) = 0 Then
    MsgBox "Please save this document first"
    Exit Sub
End If
Set oTemplate = ActiveDocument.AttachedTemplate
With Application.FileSearch
    .NewSearch
    .LookIn = sFolder
    .SearchSubFolders = False
    .FileType = msoFileTypeWordDocuments
    If Not .Execute( ) = 0 Then
        For i = 1 To .FoundFiles.Count
            sFileFullName = .FoundFiles(i)
            sFileName = Right(sFileFullName, _
                        (Len(sFileFullName) - _
                        (InStrRev(sFileFullName, "\"))))
    ....

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint