PDA

View Full Version : Problems inserting an image watermark



intersilver
11-21-2010, 07:50 PM
Hi all

I'm trying to insert an image watermark into my Word 2007 document using a macro, and it's giving me some strange problems...
(The code below is based on what I found on the web - but the same thing happens even when I try to record the macro myself)

The image seems to be inserted just fine. But after the macro is finished, two things happen:
1. Word slows down to a crawl as soon as I type anything (using all available CPU cycles).

2. The watermark cannot be removed or changed manually... Word behaves as if the document doesn't have a watermark at all.
Of course, these problems do not occur if I insert a watermark manually (from the Page Layout ribbon).

In short, it seems like the macro is doing something very different than the manual action.
Even though I tried to record the exact same manual action into a macro, it fails in exactly the same way... strange eh?

Can anyone help??

Sub wmark_try()

If ActiveWindow.View.SplitSpecial = wdPaneNone Then
ActiveWindow.ActivePane.View.Type = wdPrintView
Else
ActiveWindow.View.Type = wdPrintView
End If

Dim oHeader As HeaderFooter
Set oHeader = ActiveDocument.Sections(1) _
.Headers(wdHeaderFooterPrimary)

Application.ScreenUpdating = False

With oHeader
.Shapes.AddPicture FileName:= "D:\Graphics\background.jpg", _
LinkToFile:=False, SaveWithDocument:=True
With .Shapes(1)
.name = "MyWMark"
.PictureFormat.Brightness = 0.5
.PictureFormat.Contrast = 0.5
.LockAspectRatio = True
.Height = InchesToPoints(11.1)
.Width = InchesToPoints(8.6)
.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapNone
.WrapFormat.Type = 3
.RelativeHorizontalPosition = _
wdRelativeVerticalPositionMargin
.RelativeVerticalPosition = _
wdRelativeVerticalPositionMargin
.Left = wdShapeCenter
.Top = wdShapeCenter
End With
End With

Application.ScreenUpdating = True

End Sub