Use Word VBA to Update Footers in Folders and Subfolders
Question details
Update footers in Word documents stored in a folder and its subfolders using a reusable VBA routine.

- Product
- Microsoft Word VBA
- Device & OS
- not provided
- Scenario
- A user wants to search a root folder recursively and pass each matching document to a procedure that edits its footer.
- Observed behavior
- The desired macro opens each matching document, applies the footer update, and saves the changes.
Identify the root folder and the file extension to process, and test the macro on a small set of copies first. The example replaces existing footer content and skips protected or read-only documents.
Run a recursive Word VBA macro with a footer callback
Use this modular example to find matching documents and replace their existing footer content.
The folder routine accepts a root path, callback name, file pattern, and subfolder flag. The callback opens and edits each matching document.
This example uses Windows FileSystemObject. It replaces the text and other content in each existing, unlinked footer; linked footers inherit the change from the preceding section.
In Word, press Alt+F11, select a macro-enabled document or template in the Project pane, and choose Insert > Module.
Paste the following code into the module: Option Explicit Public Sub RunFooterUpdate() ProcessFolder "C:\Your\Root\Folder", "UpdateFooter", "*.docx", True End Sub Public Sub ProcessFolder(ByVal rootPath As String, ByVal callbackName As String, Optional ByVal pattern As String = "*.docx", Optional ByVal includeSubfolders As Boolean = True) Dim fso As Object, folder As Object, file As Object, subfolder As Object Set fso = CreateObject("Scripting.FileSystemObject") Set folder = fso.GetFolder(rootPath) For Each file In folder.Files If Left$(file.Name, 2) <> "~$" Then If LCase$(file.Name) Like LCase$(pattern) Then Application.Run callbackName, CStr(file.Path) End If End If Next file If includeSubfolders Then For Each subfolder In folder.SubFolders ProcessFolder CStr(subfolder.Path), callbackName, pattern, True Next subfolder End If End Sub Public Sub UpdateFooter(ByVal filePath As String) Dim doc As Document, sec As Section, footer As HeaderFooter On Error GoTo Failed Set doc = Documents.Open(FileName:=filePath, ReadOnly:=False, AddToRecentFiles:=False, Visible:=False) If doc.ReadOnly Or doc.ProtectionType <> wdNoProtection Then Debug.Print "Skipped read-only or protected: " & filePath doc.Close SaveChanges:=wdDoNotSaveChanges Exit Sub End If For Each sec In doc.Sections For Each footer In sec.Footers If footer.Exists Then If Not footer.LinkToPrevious Then footer.Range.Text = "Your footer text" End If Next footer Next sec doc.Save doc.Close SaveChanges:=wdDoNotSaveChanges Exit Sub Failed: Debug.Print "Failed: " & filePath & " - " & Err.Description On Error Resume Next If Not doc Is Nothing Then doc.Close SaveChanges:=wdDoNotSaveChanges End Sub
Replace C:\Your\Root\Folder with the actual folder path and replace Your footer text with the desired content. Change *.docx to *.doc for legacy Word documents, or run the macro separately for each pattern. Set True to False to search only the root folder.
Place the cursor inside RunFooterUpdate and press F5. Open the Immediate window with Ctrl+G to review skipped documents and file-level errors, then open several processed documents in Word to verify their footers.

Edit Word documents with WPS Writer
WPS Office is a free, lightweight alternative with a familiar interface for opening and editing Word documents. Its format compatibility makes it easy to move existing files into WPS Writer, although it does not fix or guarantee compatibility with this Microsoft Word VBA macro.

Frequently Asked Questions
How do I search only the selected folder?
In RunFooterUpdate, change the final argument in the ProcessFolder call from True to False.
Can the macro process both DOC and DOCX files?
Run ProcessFolder once with the pattern *.doc and again with *.docx. Check the results for each group in the VBA editor's Immediate window.
Why were some documents skipped?
The callback skips documents that open read-only or are protected. Press Ctrl+G in the VBA editor to see the affected paths, then check each document's permissions and protection in Word.
Will the macro preserve existing footer content?
No. The example replaces existing content in each unlinked footer. Edit the UpdateFooter procedure if you need to append text or preserve fields, images, and formatting.




