Knowledge.ToString()

MS Word: Remove watermark from all Word pages using VBA

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

Comments

11 responses to “MS Word: Remove watermark from all Word pages using VBA”

  1. Alana Avatar
    Alana

    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 Avatar
    Jessica

    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 Avatar
    Hugo

    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 Avatar
    James Kenders

    Great job. How do you research this stuff?

  5. Laura Avatar
    Laura

    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 Avatar
    Jane Hester

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

  7. Madhan Avatar
    Madhan

    hi Vishal
    how to do this in word 2007.

  8. Micheal Smith Avatar
    Micheal Smith

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

  9. alex Avatar
    alex

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

  10. alex Avatar
    alex

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

  11. dmang Avatar
    dmang

    Thanks
    Worked like a charm…
    dm

Leave a Reply

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