MS Word: Remove watermark from all Word pages using VBA

Category: MS WordTags: , ,

You can create watermark in MS Word document by going to Format Menu > Background > Printed Watermarks… Here you will be able to set Text Watermark in each page. Now if you want to remove the watermark from all pages, use the following VBA script.

Dim section As Word.section
Dim pheadertype As Long
Dim hdr As Range
Dim sp As Shape
Dim str As String
For Each section In ActiveDocument.Sections
   With section
      Set hdr = .Headers(wdHeaderFooterFirstPage).Range
      For Each sp In hdr.ShapeRange
         str = sp.Name
         If InStr(str, "PowerPlusWaterMarkObject") > 0 Then
            sp.Visible = msoFalse
          End If
       Next
       Set hdr = .Headers(wdHeaderFooterPrimary).Range
       For Each sp In hdr.ShapeRange
          str = sp.Name
          If InStr(str, "PowerPlusWaterMarkObject") > 0 Then
              sp.Visible = msoFalse
          End If
        Next
    End With
 Next

Share

11 comments

Your email address will not be published. Required fields are marked *

  1. Alana says:

    Wow and thanks Vishal; very much appreciated! I’m new to VBA in Word and Excel, and this was perfect in Word! Haven’t done macros in over 2 decades and needed to jump back on it.

  2. Jessica says:

    The code as written doesn’t handle sections with different odd and even headers. You’d have to add this to the main loop:
    Set hdr = .Headers(wdHeaderFooterOdd).Range.
    For Each sp In hdr.ShapeRange
    str = sp.Name
    If InStr(str, “PowerPlusWaterMarkObject”) > 0 Then
    sp.Visible = msoFalse
    End if
    Next

    and something similar using .Headers(wdHeaderFooterEven).Range.

  3. Hugo says:

    The code specified works fine i.e. no errors BUT why, when I have a 3 page single section document, does the document end up with the watermark removed from page 1 and 3 but not from page2?

  4. James Kenders says:

    Great job. How do you research this stuff?

  5. Laura says:

    Thank you this is very helpful. I used the “PowerPlusWaterMarkObject” string to help me get a handle on watermarks in the section and then changed the text to what I wanted!

  6. Jane Hester says:

    This if for a MS Word document. I have WordPerfect.

  7. Madhan says:

    hi Vishal
    how to do this in word 2007.

  8. Micheal Smith says:

    Good work Vishal. You have created watermark in Microsoft word that benefit many people. Well done!!
    __________________________________________________________________________
    Micheal Smith

  9. alex says:

    Good work Vishal. you have done a great job and your invention become useful to people who use Microsoft word.
    _________________________________________________________________________
    Alex

  10. alex says:

    Good work Vishal. you have done a great job and your invention become useful to people who use Microsoft word

  11. dmang says:

    Thanks
    Worked like a charm…
    dm