View Single Post
 
Old 03-07-2012, 09:45 AM
patidallas22 patidallas22 is offline Windows XP Office 2007
Novice
 
Join Date: Mar 2012
Posts: 12
patidallas22 is on a distinguished road
Default Word Macro - change date in footer for all files in a folder

I am trying to change the date in the footer for all the files in a specific folder and put in the following macro, but I must have done something wrong because it is not working. Our drive on our server is "W" but I don't know what I have input incorrectly. I saved my macro as "ReplaceDateFooter". Thanks for your help!

Code:
Sub ReplaceDateFooter()
Const D = "W:\PublicWorks\Projects\COF_City_of_Ft_Worth\Specs to play with"
Const Find = "July 1, 2011"
Const Replace = "March 1, 2012"
Dim doc As Document
Dim wd As New Word.Application
Dim fn As String
Dim rng As Range
Dim hf As HeaderFooter
Dim s As Section
fn = Dir(D & "*.doc")
While fn <> ""
  Set doc = wd.Documents.Open(D & fn)
  Debug.Print fn
  For Each s In doc.Sections
    For Each hf In s.Footers
      Set rng = hf.Range
      With rng.Find
        .Text = Find
        .Replacement.Text = Replace
        .Execute Replace:=wdReplaceAll
      End With
    Next
  Next
  doc.Save
  doc.Close
  fn = Dir
Wend
wd.Quit
End Sub

Last edited by macropod; 03-08-2012 at 10:10 PM. Reason: Added code structure & tags
Reply With Quote