![]() |
|
#1
|
|||
|
|||
![]()
Paul,
They are changing headers and footers. Attaching a new template will do nothing. They need to copy the body of the template into a new template with the new headers/footers. Any chance you could come up with code that will: For each template in a folder...
|
#2
|
||||
|
||||
![]() Quote:
As for the headers/footers, if the content differs, the processing of that can be added to the code: Code:
Sub UpdateDocumentsAndTemplates() Application.ScreenUpdating = False Dim strFolder As String, strFile As String, strDocNm As String, wdDoc As Document Dim strTmplt As String, wdTmp As Document, HdFt As HeaderFooter strDocNm = ActiveDocument.FullName strFolder = GetFolder If strFolder = "" Then Exit Sub strTmplt = "C:\Templates\SomeTemplate.dotm" Set wdTmp = Documents.Open(strTmplt) 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 .AttachedTemplate = strTmplt .CopyStylesFromTemplate (strTmplt) With .Sections(1) For Each HdFt In .Headers If HdFt.Exists Then If wdTmp.Sections(1).Headers(HdFt.Index).Exists Then HdFt.Range.FormattedText = wdTmp.Sections(1).Headers(HdFt.Index).Range.FormattedText End If End If Next For Each HdFt In .Footers If HdFt.Exists Then If wdTmp.Sections(1).Footers(HdFt.Index).Exists Then HdFt.Range.FormattedText = wdTmp.Sections(1).Footers(HdFt.Index).Range.FormattedText End If End If Next 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 [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Need to find/replace text in many word files - but text is in embedded word files | semple.13 | Word VBA | 5 | 11-03-2015 01:20 PM |
![]() |
cole790 | Word | 1 | 12-08-2013 03:55 PM |
Merging pst files and moving to NAS drive | riteoh | Outlook | 0 | 10-02-2012 05:20 AM |
![]() |
Stephen0352 | Word | 4 | 03-05-2012 01:29 AM |
moving data files | g48dd | Outlook | 2 | 06-17-2011 01:18 PM |