VBA & Macro Problems

Add a Picture Watermark to Multiple Word Documents with VBA

Rana GarciaRana Garcia Nov 22, 2026 868 views

Question details

Add a custom PNG watermark to multiple Word documents, including first pages, with control over its size and position.

Add a Picture Watermark to Multiple Word Documents with VBA
Product
Microsoft Word
Device & OS
not provided
Scenario
Batch-process Word documents with VBA and save the watermark in each file.
Observed behavior
The existing macro does not watermark the first page or scale the picture as expected. The user also wants to remove watermarks in bulk.
Before you start

On Windows, place a few test DOCX files in a separate folder and keep the PNG image outside that folder. Save the macro in a separate macro-enabled document or template, and run it only on trusted files you are authorized to modify.

Solution 1Recommended

Batch-add a 150% picture watermark with Word VBA

Use this Windows desktop Word macro to add a centered PNG watermark to DOCX files, including distinct first-page and even-page headers.

The macro processes DOCX files in the selected folder, not its subfolders. It unlinks active headers from previous sections so it can update each section; this changes the documents' header-link settings.

The picture is scaled to 150% of its original size with its aspect ratio locked. Brightness and contrast settings create a faded effect; adjust them if the image is too faint.

1
Open the VBA editor

In desktop Word on Windows, press Alt+F11. In the VBA editor, select Insert > Module in a macro-enabled document or template that is outside the folder to be processed.

2
Paste the macro

Paste the following code into the module: Option Explicit Public Sub BatchAddPictureWatermark() Dim picker As FileDialog Dim folder As String, picture As String, file As String Dim doc As Document, sec As Section, hdr As HeaderFooter Dim shp As Shape, i As Long, oldSecurity As MsoAutomationSecurity Dim message As String Set picker = Application.FileDialog(msoFileDialogFolderPicker) picker.Title = "Select the folder containing DOCX files" If picker.Show <> -1 Then Exit Sub folder = picker.SelectedItems(1) If Right$(folder, 1) <> "\" Then folder = folder & "\" Set picker = Application.FileDialog(msoFileDialogFilePicker) picker.Title = "Select the PNG watermark" picker.AllowMultiSelect = False picker.Filters.Clear picker.Filters.Add "PNG images", "*.png" If picker.Show <> -1 Then Exit Sub picture = picker.SelectedItems(1) oldSecurity = Application.AutomationSecurity On Error GoTo Failed Application.AutomationSecurity = msoAutomationSecurityForceDisable file = Dir$(folder & "*.docx") Do While file <> "" If Left$(file, 2) <> "~$" Then Set doc = Documents.Open(FileName:=folder & file, AddToRecentFiles:=False) For Each sec In doc.Sections For i = 1 To 3 Set hdr = sec.Headers(i) If hdr.Exists Then If sec.Index > 1 Then hdr.LinkToPrevious = False For Each shp In hdr.Shapes If shp.Name = "BatchPictureWatermark" Then shp.Delete Next shp Set shp = hdr.Shapes.AddPicture(FileName:=picture, LinkToFile:=False, SaveWithDocument:=True, Anchor:=hdr.Range) With shp .Name = "BatchPictureWatermark" .LockAspectRatio = msoTrue .ScaleWidth 1.5, msoTrue .PictureFormat.Brightness = 0.85 .PictureFormat.Contrast = 0.15 .WrapFormat.Type = wdWrapBehind .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage .RelativeVerticalPosition = wdRelativeVerticalPositionPage .Left = wdShapeCenter .Top = wdShapeCenter End With End If Next i Next sec doc.Close SaveChanges:=wdSaveChanges Set doc = Nothing End If file = Dir$() Loop Application.AutomationSecurity = oldSecurity MsgBox "Finished processing DOCX files." Exit Sub Failed: message = Err.Description On Error Resume Next If Not doc Is Nothing Then doc.Close SaveChanges:=wdDoNotSaveChanges Application.AutomationSecurity = oldSecurity MsgBox "Processing stopped: " & message End Sub

3
Run and check the results

In Word, choose View > Macros, run BatchAddPictureWatermark, and select the document folder and PNG when prompted. Open the test files and check the first, even, and later section pages before processing the rest.

Batch-add a 150% picture watermark with Word VBA
File types and interruptions: The macro processes only .docx files. To process another Word file type, change the Dir$ pattern and test it separately. A protected, locked, or otherwise unopenable file can stop the batch; documents already saved remain changed.
Free Microsoft Office alternative

Work with Word documents in WPS Writer

WPS Office is a free, lightweight alternative for working with Word documents in a familiar interface. Open compatible files in WPS Writer for a convenient transition, while using Microsoft Word for the VBA batch macro described above.

Open and edit Microsoft Word DOCX and DOC filesWork with document formatting and page layouts in WPS WriterUse a familiar interface when moving from Microsoft OfficeAccess a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why is the watermark missing from the first page?

A section can use a separate first-page header. The original macro adds the picture only to the primary header; the revised macro also checks other active headers in each section.

How do I change the watermark scale?

In the VBA module, change .ScaleWidth 1.5, msoTrue to another factor, such as 1 for 100% or 2 for 200%. With LockAspectRatio enabled, the height changes proportionally.

Will running the add macro twice create duplicate watermarks?

The macro first deletes shapes named BatchPictureWatermark from each active header, then adds a new one. It does not remove watermarks with other names.

Can I process DOC or DOCM files instead?

Change the *.docx pattern in the Dir$ line to the desired extension and test on separate files first. The supplied macro handles one extension per run and does not search subfolders.

Does the removal method delete every watermark?

No. It deletes only header shapes named BatchPictureWatermark. Other watermark shapes or background images require separate identification and removal.