Watermark macro silently fails

J

JimC

Hi,

I'm using MS Word 2003 SP2 on WIndows XP SP2 with Word macro security
set to "medium".

I record a macro, then choose "Format", "Background", "Printed
Watermark..." from the menu. Next, I set the text to "ZZZ" and click
"OK". Finally, I turn off macro recording.

Next, I went back and changed the watermark text to "WWW" using the
same procedure as above (without macro recording).

Finally, I chose the macro I recorded and ran it. Although the screen
flashes,etc the watermark text is unchanged (I expect it to go from
reading "WWW" to "ZZZ").

It appears that the VBA code generated by the macro does not work. Does
anyone know what is wrong with the generated code and how to fix it?
Can anyone else reproduce this behavior on their computer?

Many thanks in advance for your assistance.
 
J

Jay Freedman

Hi,

I'm using MS Word 2003 SP2 on WIndows XP SP2 with Word macro security
set to "medium".

I record a macro, then choose "Format", "Background", "Printed
Watermark..." from the menu. Next, I set the text to "ZZZ" and click
"OK". Finally, I turn off macro recording.

Next, I went back and changed the watermark text to "WWW" using the
same procedure as above (without macro recording).

Finally, I chose the macro I recorded and ran it. Although the screen
flashes,etc the watermark text is unchanged (I expect it to go from
reading "WWW" to "ZZZ").

It appears that the VBA code generated by the macro does not work. Does
anyone know what is wrong with the generated code and how to fix it?
Can anyone else reproduce this behavior on their computer?

Many thanks in advance for your assistance.

Hi Jim,

I can't get the recorded macro to fail *silently* -- it blows up when
it tries to assign a name to the shape (which isn't needed anyway).
When I comment out that line, the macro runs but puts the new
watermark on top of the old one instead of replacing it.

This isn't unusual; I wrote a whole article about how the recorder
gets things wrong and/or horribly inefficient
(http://www.word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm).

Here's a fixed version:

Sub Macro1()
Dim theText As String
Dim oRg As Range

theText = InputBox$("Text for watermark:")
If Len(theText) = 0 Then Exit Sub

Set oRg = ActiveDocument.Sections(1) _
.Headers(wdHeaderFooterPrimary).Range
With oRg
If .ShapeRange.Count Then .ShapeRange.Delete
ActiveDocument.Sections(1) _
.Headers(wdHeaderFooterPrimary).Shapes _
.AddTextEffect PowerPlusWaterMarkObject1, _
theText, "Times New Roman", 1, False, False, 0, 0, oRg
With .ShapeRange
'.Name = "PowerPlusWaterMarkObject1"
.TextEffect.NormalizedHeight = False
.Line.Visible = False
.Fill.Visible = True
.Fill.Solid
.Fill.ForeColor.RGB = RGB(192, 192, 192)
.Fill.Transparency = 0.5
.Rotation = 315
.LockAspectRatio = True
.Height = InchesToPoints(2.11)
.Width = InchesToPoints(6.34)
.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapNone
.WrapFormat.Type = wdWrapNone
.RelativeHorizontalPosition = _
wdRelativeVerticalPositionMargin
.RelativeVerticalPosition = _
wdRelativeVerticalPositionMargin
.Left = wdShapeCenter
.Top = wdShapeCenter
End With
End With
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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