MS Word file styles automatically update with external document

mhtmicrosoft wordsharepoint

In MS Word we have a template document (template1.docm). This document is use in SharePoint by many users to write thousands of procedure documents, saved as .mht documents.

As we update styles in template we would like to update all these other documents created from it.

Is it possible to update styles in just this one template file and have all these other files automatically update?

If not, what else can I do to update these thousands of documents with the changes to the template file?

Best Answer

I will try to outline an approach to the problem using a VBA macro, warning that it is entirely theoretical and untested.

The idea is to create a work document containing a VBA macro that does the work of re-attaching the template to all the documents in a folder, after asking for the folder.

Do not put the file containing this macro in the folder you want to process, or it will process itself.

Here is the macro :

Sub UpdateDocuments()
Dim strFolder As String, strFile As String, strCurDoc As Document, strTemplate As String
strFolder = GetFolder
strTemplate = "C:\path to template\template.dot"
If strFolder = "" Then Exit Sub
Application.ScreenUpdating = False
strFile = Dir(strFolder & "\*.docx", vbNormal)
While strFile <> ""
  Set strCurDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
  strCurDoc.AttachedTemplate = strTemplate
  strCurDoc.Close wdSaveChanges
  End With
  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