#1
|
|||
|
|||
Changing multpile documents
Hi, I have to add a footer with an updating date field on every document in our drive. I can do this manually but is very slow going. Is there an easier way to do this? Any help would be appreicated Jay |
#2
|
||||
|
||||
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Open documents changing font on subsequent templates | mikmak | Word | 7 | 03-04-2012 08:23 PM |
total slack not changing when changing duration | ketanco | Project | 1 | 02-11-2012 07:23 AM |
changing | gsrikanth | Excel Programming | 8 | 02-08-2012 09:09 PM |
Changing the From field | jerem | Outlook | 2 | 10-29-2010 03:04 PM |
changing font size without changing leading | carolns | Word | 1 | 09-14-2009 12:30 PM |