Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-07-2012, 09:45 AM
patidallas22 patidallas22 is offline Word Macro - change date in footer for all files in a folder Windows XP Word Macro - change date in footer for all files in a folder Office 2007
Novice
Word Macro - change date in footer for all files in a folder
 
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
  #2  
Old 03-08-2012, 10:35 PM
macropod's Avatar
macropod macropod is online now Word Macro - change date in footer for all files in a folder Windows 7 64bit Word Macro - change date in footer for all files in a folder Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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 patidallas,

One thing you'll need is a '\' on the end of your path; otherwise 'D & fn' simply appends the document name to the end of the path name.

PS: When posting code, please use code tags (on the Advanced tab)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 03-09-2012, 08:14 AM
patidallas22 patidallas22 is offline Word Macro - change date in footer for all files in a folder Windows XP Word Macro - change date in footer for all files in a folder Office 2007
Novice
Word Macro - change date in footer for all files in a folder
 
Join Date: Mar 2012
Posts: 12
patidallas22 is on a distinguished road
Default

Thanks Macropod, That worked great, I appreciate your help!

Last edited by patidallas22; 03-09-2012 at 08:16 AM. Reason: Add smiley
Reply With Quote
Reply

Tags
change date, macro, vba word

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word macro doesn't change font color Spideriffic Word VBA 8 11-04-2015 03:47 AM
Word Macro - change date in footer for all files in a folder Change Footer style msm6165 PowerPoint 1 07-17-2011 03:40 PM
Word Macro - change date in footer for all files in a folder Auto Change Date in Word Document??? dssxxxx Word 2 01-06-2011 05:50 AM
Cannot stop the date being printed in the footer Ubtree Outlook 0 10-13-2007 11:49 AM
Word Macro - change date in footer for all files in a folder Imported message date change to today's date promark Outlook 1 12-23-2005 07:21 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:44 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft