Document Editing Problems

Remove Watermarks from Multiple Word and RTF Documents with VBA

Khadija KhanKhadija Khan Nov 20, 2026 869 views

Question details

Remove a fixed watermark from a large collection of Word and RTF documents without editing each file manually.

Remove Watermarks from Multiple Word and RTF Documents with VBA
Product
Microsoft Word
Device & OS
not provided
Scenario
Documents in a folder tree contain a recurring watermark, and the user wants to automate its removal.
Observed behavior
Manual removal across thousands of documents is impractical, and watermark storage can differ by file format and watermark type.
Before you start

Inspect several representative DOC, DOCX, and RTF files to confirm that the watermark is a floating text shape in a header and note its exact text. Use a separate test folder containing copies, and keep a complete backup before processing the original folder tree.

Solution 1Recommended

Remove matching text watermarks with a Word VBA macro

Use this Windows desktop Word macro when the watermark is a header text shape with the same text in each document.

The macro searches DOC, DOCX, and RTF files in the selected folder and its subfolders. It deletes header shapes whose text exactly matches the specified watermark, ignoring case, and saves changed files in their existing formats.

It does not remove picture watermarks, grouped shapes, body objects, or watermarks stored in other ways. Files that are protected, read-only, or otherwise cannot be edited may be skipped or reported as errors.

1
Open the VBA editor

In desktop Word for Windows, press Alt+F11. In the Project pane, select Normal or a trusted macro-enabled document, then choose Insert > Module.

2
Add the macro

Paste the following code into the module. Replace CONFIDENTIAL with the exact watermark text you found in the test files: Option Explicit Private changedCount As Long Private errorCount As Long Private Const WATERMARK_TEXT As String = "CONFIDENTIAL" Sub RemoveMatchingWatermarks() Dim picker As FileDialog Dim rootPath As String Dim oldAlerts As WdAlertLevel changedCount = 0 errorCount = 0 Set picker = Application.FileDialog(4) picker.Title = "Select the folder to process" If picker.Show <> -1 Then Exit Sub rootPath = picker.SelectedItems(1) oldAlerts = Application.DisplayAlerts On Error GoTo Failed Application.DisplayAlerts = wdAlertsNone WalkFolder rootPath Application.DisplayAlerts = oldAlerts MsgBox changedCount & " files changed; " & errorCount & " errors. Check the Immediate window (Ctrl+G) for details." Exit Sub Failed: Application.DisplayAlerts = oldAlerts MsgBox "Processing stopped: " & Err.Description & vbCrLf & "Files changed: " & changedCount End Sub Private Sub WalkFolder(ByVal folderPath As String) Dim fso As Object, folder As Object, file As Object, subfolder As Object Dim ext As String Set fso = CreateObject("Scripting.FileSystemObject") Set folder = fso.GetFolder(folderPath) For Each file In folder.Files ext = LCase$(fso.GetExtensionName(file.Name)) If Left$(file.Name, 2) <> "~$" Then If ext = "doc" Or ext = "docx" Or ext = "rtf" Then ProcessFile file.Path End If Next file For Each subfolder In folder.SubFolders WalkFolder subfolder.Path Next subfolder End Sub Private Sub ProcessFile(ByVal filePath As String) Dim doc As Document, sec As Section, hdr As HeaderFooter Dim i As Long, removed As Long On Error GoTo FileError 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 errorCount = errorCount + 1 Else For Each sec In doc.Sections For Each hdr In sec.Headers If hdr.Exists Then For i = hdr.Shapes.Count To 1 Step -1 If IsMatchingText(hdr.Shapes(i)) Then hdr.Shapes(i).Delete removed = removed + 1 End If Next i End If Next hdr Next sec If removed > 0 Then doc.Save changedCount = changedCount + 1 Debug.Print "Changed: " & filePath End If End If doc.Close SaveChanges:=wdDoNotSaveChanges Exit Sub FileError: Debug.Print "Error: " & filePath & " - " & Err.Description errorCount = errorCount + 1 On Error Resume Next If Not doc Is Nothing Then doc.Close SaveChanges:=wdDoNotSaveChanges End Sub Private Function IsMatchingText(ByVal shp As Shape) As Boolean Dim shapeText As String On Error GoTo NotMatching If shp.TextFrame.HasText Then shapeText = shp.TextFrame.TextRange.Text shapeText = Replace(shapeText, vbCr, "") shapeText = Replace(shapeText, vbLf, "") IsMatchingText = (StrComp(Trim$(shapeText), Trim$(WATERMARK_TEXT), vbTextCompare) = 0) End If NotMatching: End Function

3
Run on test copies

Place the cursor inside RemoveMatchingWatermarks and press F5. Select the test folder in the folder picker; the macro also processes its subfolders.

4
Review results before scaling up

In the VBA editor, press Ctrl+G to inspect the Immediate window for changed files and errors. Open representative output files in Word, check their watermarks and formatting, and only then run the macro on the intended folder tree.

Remove matching text watermarks with a Word VBA macro
Matching text can be removed from other header shapes: The macro deletes any header shape with the specified text, not just shapes created by Word's Watermark command. Adjust the approach if that text also appears in legitimate header objects.
Free Microsoft Office alternative

Review Word Documents with WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for opening and editing documents. Its format compatibility helps you move existing files into your workflow, though it does not fix or replace the Microsoft Word VBA macro above.

Open documents to review watermark removal and formatting.Works with Microsoft Word formats including DOC and DOCX, as well as RTF.Use a familiar document-editing interface for an easier transition.Access a free, lightweight office suite for everyday editing.
microsoft office alternative - wps office

Frequently Asked Questions

Will the macro remove picture watermarks?

No. It matches text in floating header shapes. Inspect a picture watermark by double-clicking the header in Word; picture-based or grouped watermarks require a different approach.

Does the macro process subfolders?

Yes. After you select a folder in the picker, it searches that folder and its subfolders for DOC, DOCX, and RTF files. Test with a small folder tree first.

Why did a document still have its watermark after the macro ran?

The watermark text may not match the WATERMARK_TEXT constant, or it may not be a standalone text shape in a header. The file may also be protected or read-only. Press Ctrl+G in the VBA editor to check the Immediate window for reported errors.

Will the macro change the document's file format?

The macro uses Word's Save command rather than Save As, so it attempts to save each changed document in its existing format. Verify representative DOC, DOCX, and RTF outputs for formatting changes before processing the full collection.