Invalid procedure call

A

Associates

Hi,

I wonder if i could get some help with macro. I was trying to create a macro
that would put a watermark in the background of a document. The following
below shows the code that i got from running macro recording.

ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes.AddTextEffect(PowerPlusWaterMarkObject1, _
"DRAFT ONLY", "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(3.44)
Selection.ShapeRange.Width = CentimetersToPoints(17.21)
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

when i run this macro, i got a message error that read "Invalid procedure
call or argument". I think this might be caused by the variable "Gray" in the
code as VBA does not know what it is. I wonder what to use to represent the
color Gray.

Any help would be greatly appreciated.

Thank you in advance
 
G

Greg Maxey

Associates one and all,

Yes. You will need to correctly define the forecolor either with using RGB
components, a long value or some color constant:

With Selection
.HeaderFooter.Shapes.AddTextEffect(1, _
"DRAFT ONLY", "Times New Roman", 1, False, False, 0, 0).Select
With .ShapeRange
.Name = "PowerPlusWaterMarkObject1"
.TextEffect.NormalizedHeight = False
.Line.Visible = False
With .Fill
.Visible = True
.Solid
'the Red, Green, Blue components of some shade of grey
.ForeColor.RGB = RGB(152, 152, 152)
'or some long value representing a shade of grey
.ForeColor = 12632256
'or some shade of grey color constant.
.ForeColor = wdColorGray25
.Transparency = 0.5
End With
 
A

Associates

Thank you Greg for your reply.

It works really well, Greg. Thanks.

But if i may ask you one more question. So far it only applies to one page
which is the first page of the document. How should i change the code so that
it would apply to whole document.

ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

' and followed by your code ...

' end it with the following
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

Thank you in advance
 
G

Greg Maxey

Associates one and all,

The complexity of the shapes collection in the header and footer story
ranges of a Word document is something that boogles my mind and I can't
explain it. If I am not mistaken then I think you might be the same poster
that is trying to but a DRAFT watermark on a word document and can't figure
out why your remove procedure isn't working (a separate post). If you will
send me e-mail via my webpage feedback I will send you a document with a
working example.
 
A

Associates

Thank you Greg for your reply.

Yes, i think you referred to me as the poster. I did post a question in
regards to removing a straight line that was grayed out on the background of
my report document. To cut long story short, i did not really fix it but it
was good enough for me. What i did was to copy the whole document, except the
last few blank pages which stuffed up my report, to a new document and it did
exactly what i wanted it to (that is without any empty pages at the last of
the report).

I would love to send that report to you to investigate but due to the
company's disclosure policy, i am afraid if i can do that. Sorry Greg.

So coming back to the Draft watermark issue, is it very complicated to apply
that to the rest of the document rather than just on the first page due to
the header/footer? Are there any way out for this?

Thank you in advance
 
G

Greg Maxey

Perhaps I don't understand what you are trying to do. I have put together a
little AddIn that applies watermarks to each header story (first, even, odd)
so the watermark appears on each page. If you send me e-mail then I will
send you the AddIn.
 

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