Thread: [Solved] Changing multpile documents
View Single Post
 
Old 02-27-2012, 03:55 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Jay,

Here's a macro to try. Simply run the UpdateDocuments procedure, select the folder to process and let the code run. You may need to change the '"DDDD, D MMMM YYYY" string to get the date format you want, so try it on a folder containing just one document first. Note also that the code won't add the date field to a footer that already has one.
Code:
Sub UpdateDocuments()
Application.ScreenUpdating = False
Dim strFolder As String, strFile As String, wdDoc As Document, oFld As Field, bFnd As Boolean
strFolder = GetFolder
If strFolder = "" Then Exit Sub
strFile = Dir(strFolder & "\*.doc", vbNormal)
While strFile <> ""
  Set wdDoc = Documents.Open(FileName:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
  With wdDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range
    bFnd = False
    For Each oFld In Fields
      If oFld.Type = wdFieldDate Then
        bFnd = True
        Exit For
      End If
    Next
    If bFnd = False Then
      .Fields.Add Range:=.Characters.Last, Type:=wdFieldDate, _
        Text:="\@ " & Chr(34) & "DDDD, D MMMM YYYY" & Chr(34), _
        PreserveFormatting:=False
    End If
  End With
  wdDoc.Close SaveChanges:=True
  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
If you don't know how to install/use a macro see: http://www.gmayor.com/installing_macro.htm
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote