Deleting watermarks

N

Neil Humphries

I need to delete any existing watermark, standard or custom before inserting
a new watermark. When I recorded a macro, I got the following:

Sub DelWatermark()
ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes("PowerPlusWaterMarkObject25706312").Select
Selection.Delete
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
WordBasic.RemoveWatermark
End Sub

The identifier "PowerPlusWaterMarkObject25706312" is unique to the
particular watermark that I deleted. How do I delete any watermark?

I found these building block type constants, but don't know how to make use
of them.
wdTypeCustomWatermarks
wdTypeWatermarks

Most of the documents only have 1 section, but I can't guarantee that. Would
the following code loop through all the sections for me?

Dim I As Integer
Dim Isectioncount As Integer
Set Isectioncount = ActiveDocument.Sections.Count
For I = 0 To Isectioncount
' Code to remove watermark
Next I
 
D

Doug Robbins - Word MVP

Try Shapes(1). If the watermark is the only shape in the header, that
should delete it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
N

Neil Humphries

In this case, the watermark is the only shape in the header so your solution
works.
In the case where there are other shapes, is there something that
distinguishes a watermark from the other shapes? I would anticipate that the
other shapes reside in the defined header or footer regions and not behind
the main story text. Is there a particular property that could be evaluated
to determine this?

For example: Selection.ShapeRange.WrapFormat.AllowOverlap = True
 
D

dmjones500

Neil Humphries said:
I need to delete any existing watermark, standard or custom before inserting
a new watermark. When I recorded a macro, I got the following:

Sub DelWatermark()
ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes("PowerPlusWaterMarkObject25706312").Select
Selection.Delete
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
WordBasic.RemoveWatermark
End Sub

The identifier "PowerPlusWaterMarkObject25706312" is unique to the
particular watermark that I deleted. How do I delete any watermark?

I found these building block type constants, but don't know how to make use
of them.
wdTypeCustomWatermarks
wdTypeWatermarks

Most of the documents only have 1 section, but I can't guarantee that. Would
the following code loop through all the sections for me?

Dim I As Integer
Dim Isectioncount As Integer
Set Isectioncount = ActiveDocument.Sections.Count
For I = 0 To Isectioncount
' Code to remove watermark
Next I

I have written the following code that kills off all existing watermarks:

Sub DeleteAllWatermarks()

ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

Dim shapes_to_delete As New Collection

For i = 1 To Selection.HeaderFooter.Shapes.Count
If InStr(Selection.HeaderFooter.Shapes(i).Name,
"PowerPlusWaterMarkObject") > 0 Then
shapes_to_delete.Add (Selection.HeaderFooter.Shapes(i).Name)
End If
Next i

For Each i In shapes_to_delete
Selection.HeaderFooter.Shapes(i).Select
Selection.Delete
Next i

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

This code is based on that generated by the macro recorded. Note: the
WordBasic.RemoveWatermark line was removed as it doesn't appear to do
anything. It also seems to break backwards compatibility with Word 2003.

Duncan Jones
http://www.wortharead.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top