Change watermark via code

R

R Fourt

I have seen similar questions that are close to mine, but can't seem to put
it together correctly.

Here's all I want to do. The user clicks a toolbar button and the watermark
toggles between one of two choices.

The watermark is text only. The document has only one section with a header
and footer.

I've played with the code snippets posted in other questions but I don't
quite get the results I want. The macro record doesn't work at all. Arggh
 
Z

zkid

I agree with this article about why bother? Anyhow, the same article also
provided the solution to the funky problem with PowerPlus:
http://www.adras.com/Add-Watermark-macro-Variable-not-defined.t7648-105.html

Here's recorded code that works to insert a picture, then it changes the
picture to a text watermark. Of course, you need to plug in your picture
path. The bottom line is that PowerPlus needed to be replared with the mso
language you will read about in the above article.

ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes.AddPicture(FileName:= _
"C:\Documents and Settings\Administrator\My Documents\My
Pictures\Glass1.jpg" _
, LinkToFile:=False, SaveWithDocument:=True).Select
Selection.ShapeRange.Name = "WordPictureWatermark1"
Selection.ShapeRange.PictureFormat.Brightness = 0.85
Selection.ShapeRange.PictureFormat.Contrast = 0.15
Selection.ShapeRange.LockAspectRatio = True
Selection.ShapeRange.Height = InchesToPoints(9.19)
Selection.ShapeRange.Width = InchesToPoints(4.14)
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
MsgBox "added the picture"
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes("WordPictureWatermark1").Select
Selection.Delete
Selection.HeaderFooter.Shapes.AddTextEffect(msoTextEffect1, _
"ASAP", "Times New Roman", 1, False, False, 0, 0).Select
Selection.ShapeRange.Name = "msoTextEffect1"
Selection.ShapeRange.TextEffect.NormalizedHeight = False
Selection.ShapeRange.Line.Visible = False
Selection.ShapeRange.Fill.Visible = True
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.RGB = RGB(192, 192, 192)
Selection.ShapeRange.Fill.Transparency = 0.5
Selection.ShapeRange.Rotation = 315
Selection.ShapeRange.LockAspectRatio = True
Selection.ShapeRange.Height = InchesToPoints(3.05)
Selection.ShapeRange.Width = InchesToPoints(6.11)
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

MsgBox "deleted the pic and changed to text"
 

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