Macro adding a watermark

J

John Grierson

Have recorded the following macro to add a watermark:

ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView =
wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes.AddTextEffect
(PowerPlusWaterMarkObject1, _
"ASAP", "Times New Roman", 1, False, False, 0,
0).Select
Selection.ShapeRange.Name = "PowerPlusWaterMarkObject1"
Selection.ShapeRange.TextEffect.NormalizedHeight =
False
Selection.ShapeRange.Line.Visible = False
Selection.ShapeRange.Fill.Visible = True
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.RGB = Gray - 25
Selection.ShapeRange.Fill.Transparency = 0.5
Selection.ShapeRange.Rotation = 315
Selection.ShapeRange.LockAspectRatio = True
Selection.ShapeRange.Height = CentimetersToPoints(6.88)
Selection.ShapeRange.Width = CentimetersToPoints(13.77)
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 = wdShapeCenter
Selection.ShapeRange.Top = wdShapeCenter
ActiveWindow.ActivePane.View.SeekView =
wdSeekMainDocument

But playing it gives error 70 Permission denied on the 4th
line of code.

Any clues, please?

John
 
P

Peter Hewett

Hi John Grierson

You can only run this code once per document! SInce you are assigning a watermark, this
may be your intent, as you wouldn't want 2 watermarks in a document.

Line 4 of your code:
Selection.ShapeRange.Name = "PowerPlusWaterMarkObject1"

assigns the Shape object you have just created a name. That name *must* be unique. So if
you run the code a second time it fails because you already have an object using that
name.

HTH + Cheers - Peter
 
J

John Grierson

Hi Peter,

Thanks for that, but if you run the macro on a new
document then it crashes at

Selection.ShapeRange.Fill.ForeColor.RGB = Gray - 25

I can rem that out but then although the macro runs the
watermark is not added.

Any further ideas, please?

John
-----Original Message-----
Hi John Grierson

You can only run this code once per document! SInce you
are assigning a watermark, this
may be your intent, as you wouldn't want 2 watermarks in a document.

Line 4 of your code:
Selection.ShapeRange.Name = "PowerPlusWaterMarkObject1"

assigns the Shape object you have just created a name.
That name *must* be unique. So if
you run the code a second time it fails because you
already have an object using that
 
P

Peter Hewett

Hi John Grierson

I'm not convinced about the value being assigned in the statement:
Selection.ShapeRange.Fill.ForeColor.RGB = Gray - 25

I tried a variant of your code using the above and the Watermark was not visible. I used
the following instead:
Selection.ShapeRange.Fill.ForeColor.RGB = wdColorGray30

Essentially this just assigns a colour to the watermark object. So you can use any colour
you like. I've just used a value that's been predefined by Word.

Cheers - Peter


Hi Peter,

Thanks for that, but if you run the macro on a new
document then it crashes at

Selection.ShapeRange.Fill.ForeColor.RGB = Gray - 25

I can rem that out but then although the macro runs the
watermark is not added.

Any further ideas, please?

John
are assigning a watermark, this
That name *must* be unique. So if
already have an object using that

HTH + Cheers - Peter
 
J

John Grierson

Hi Peter,

Excellent, thanks - that works.

The Record a macro can be very useful but is certainly not
100% accurate.

Cheers

John
-----Original Message-----
Hi John Grierson

I'm not convinced about the value being assigned in the statement:
Selection.ShapeRange.Fill.ForeColor.RGB = Gray - 25

I tried a variant of your code using the above and the
Watermark was not visible. I used
the following instead:
Selection.ShapeRange.Fill.ForeColor.RGB = wdColorGray30

Essentially this just assigns a colour to the watermark
object. So you can use any colour
 
P

Peter Hewett

Hi John Grierson

The code it generates is crappy and verbose as well, but it can clue you in on the
Objects, Methods and Properties to be used.

Cheers - Peter


Hi Peter,

Excellent, thanks - that works.

The Record a macro can be very useful but is certainly not
100% accurate.

Cheers

John
Watermark was not visible. I used
object. So you can use any colour

HTH + Cheers - Peter
 

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