locked
Automating the application of a template to multiple files RRS feed

  • Question

  • I have ~200 documents that I would like to apply a Word 2007 template to. Instead of importing the styles, etc into each document, is there an elegant/automated way to accomplish this? Perhaps via the command line or batch file?
    Thanks, Steve
    Monday, January 31, 2011 9:56 PM

Answers

  • Had to do just that the other day with a folder full of documents

    Dim fd As FileDialog
    Dim strFolder As String
    Dim strFile As String
    Dim Doc As Document
    'Display a dialog in which the user can select the folder into which the file will be saved
    Set fd = Application.FileDialog(msoFileDialogFolderPicker)
    With fd
       .Title = "Select the folder that contains the documents."
       If .Show = -1 Then
           'The use pressed OK, so load the variable strFolder with the path to the folder selected by the user and append a path separator
           strFolder = .SelectedItems(1) & "\"
       Else
          'The user pressed Cancel
          Exit Sub
       End If
    End With
    'Close all open documents before beginning
    'Get the new title to be used for each document
    strFile = Dir(strFolder & "*.doc")
    While strFile <> ""
       'Open document
       Set Doc = Documents.Open(strFolder & strFile)
       With Doc
           .UpdateStylesOnOpen = True
           .AttachedTemplate = "Drive:\Path\TemplateName"
           .Close wdSaveChanges
       End With
       'Next file in folder
       strFile = Dir()
    Wend
     -- Hope this helps.

    Doug Robbins - Word MVP,
    dkr[atsymbol]mvps[dot]org
    Posted via the Community Bridge

    "DadoFour" wrote in message news:17bd81e7-8dc1-4224-94ce-7c0b45f8fdfc@communitybridge.codeplex.com...

    I have ~200 documents that I would like to apply a Word 2007 template to. Instead of importing the styles, etc into each document, is there an elegant/automated way to accomplish this? Perhaps via the command line or batch file?


    Thanks, Steve


    Doug Robbins - Word MVP dkr[atsymbol]mvps[dot]org
    • Marked as answer by Jennifer Zhan Thursday, February 10, 2011 1:42 AM
    Tuesday, February 1, 2011 10:35 AM