I have some vba code in Word 2003 to automatically add a watermark to
a document through a macro button.
I have adjusted it to work with Word 2007, but it adds a header space
to the top of each page.
If I manually add the watermark it does not create the header space at
the top, only when I add the watermark via the macro.
Here is the code:
ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes.AddPicture(FileName:= _
"C:\MS logo\em new logo2.png", LinkToFile:=False,
SaveWithDocument:=True) _
.Select
Selection.ShapeRange.Name = "WordPictureWatermark6034789"
Selection.ShapeRange.PictureFormat.Brightness = 0.5
Selection.ShapeRange.PictureFormat.Contrast = 0.5
Selection.ShapeRange.LockAspectRatio = True
Selection.ShapeRange.Height = InchesToPoints(0.59)
Selection.ShapeRange.Width = InchesToPoints(1.1)
Selection.ShapeRange.WrapFormat.AllowOverlap = True
Selection.ShapeRange.WrapFormat.Side = wdWrapNone
Selection.ShapeRange.WrapFormat.Type = 3
Selection.ShapeRange.RelativeHorizontalPosition = _
wdRelativeVerticalPositionMargin
Selection.ShapeRange.RelativeVerticalPosition = _
wdRelativeVerticalPositionMargin
Selection.ShapeRange.Left = 455
Selection.ShapeRange.Top = 5
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
Selection.HomeKey Unit:=wdStory
ActiveDocument.Protect Password:="mslegal", NoReset:=False,
Type:= _
wdAllowOnlyFormFields
Doug Robbins - Word MVP - 26 Oct 2007 05:16 GMT
The following code should overcome the problem (caused by selecting the
header range) and will probably also execute in less time.
With Selection.Sections(1).Headers(wdHeaderFooterPrimary).Range
.InlineShapes.AddPicture "C:\MS logo\em new logo2.png", _
LinkToFile:=False, SaveWithDocument:=True
With .ShapeRange(1)
.PictureFormat.Brightness = 0.5
.PictureFormat.Contrast = 0.5
.LockAspectRatio = True
.Height = InchesToPoints(0.59)
.Width = InchesToPoints(1.1)
.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapNone
.WrapFormat.Type = 3
.RelativeHorizontalPosition = _
wdRelativeVerticalPositionMargin
.RelativeVerticalPosition = _
wdRelativeVerticalPositionMargin
.Left = 455
.Top = 5
End With
End With

Signature
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
>I have some vba code in Word 2003 to automatically add a watermark to
> a document through a macro button.
[quoted text clipped - 31 lines]
> Type:= _
> wdAllowOnlyFormFields