Running 'watermark' macro deletes all header text

A

ableone

I am using the macro recorder to figure out how to automatically insert
a gif as a watermark. It's easy to do manually but when the resulting
macro is run, it always deletes the table and contained text that I need
in the header? That does not happen when I create the macro. Here is the
macro:

ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes.AddPicture(FileName:= _
"c:\letterhead\letterhead parts\watermark.gif" _
, LinkToFile:=False, SaveWithDocument:=True).Select
Selection.ShapeRange.Name = "WordPictureWatermark1"
Selection.ShapeRange.PictureFormat.Brightness = 0.5
Selection.ShapeRange.PictureFormat.Contrast = 0.5
Selection.ShapeRange.LockAspectRatio = True
Selection.ShapeRange.Height = InchesToPoints(10.47)
Selection.ShapeRange.Width = InchesToPoints(8.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
 
G

Gordon Bentley-Mix

I am unable to recreate the behaviour you have described. However, if it does
occur - and I have no doubt that it does - the problem may be with the use of
the Selection object. Try working with the Range object instead. Something
like this:

Sub InsertWaterMark()
Dim myRange As Range
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes _
.AddPicture "c:\letterhead\letterhead parts\watermark.gif"
Set myRange =
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.ShapeRange
With myRange
.Name = "WordPictureWatermark1"
.PictureFormat.Brightness = 0.5
.PictureFormat.Contrast = 0.5
.LockAspectRatio = True
.Height = InchesToPoints(10.47)
.Width = InchesToPoints(8.14)
.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapNone
.WrapFormat.Type = 3
.RelativeHorizontalPosition = wdRelativeVerticalPositionMargin
.RelativeVerticalPosition = wdRelativeVerticalPositionMargin
.Left = wdShapeCenter
.Top = wdShapeCenter
End With
End Sub
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 
D

Doug Robbins - Word MVP

Try

Dim myrange as Range, srange as ShapeRange
Set myrange = Selection.Sections(1).Headers(wdHeaderFooterPrimary).Range
myrange.Collapse wdCollapseEnd
Set srange = ActiveDocument.InLineShapes.AddPicture(Filename: =
"c:\letterhead\letterhead parts\watermark.gif" _
, LinkToFile:=False, SaveWithDocument:=True, Range: = myrange)
With srange
.Name = "WordPictureWatermark1"
.PictureFormat.Brightness = 0.5
.PictureFormat.Contrast = 0.5
.LockAspectRatio = True
.Height = InchesToPoints(10.47)
.Width = InchesToPoints(8.14)
.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapNone
.WrapFormat.Type = 3
.RelativeHorizontalPosition = wdRelativeVerticalPositionMargin
.RelativeVerticalPosition = wdRelativeVerticalPositionMargin
.Left = wdShapeCenter
.Top = wdShapeCenter
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
A

ableone

Try

Dim myrange as Range, srange as ShapeRange
Set myrange = Selection.Sections(1).Headers(wdHeaderFooterPrimary).Range
myrange.Collapse wdCollapseEnd
Set srange = ActiveDocument.InLineShapes.AddPicture(Filename: =
"c:\letterhead\letterhead parts\watermark.gif" _
, LinkToFile:=False, SaveWithDocument:=True, Range: = myrange)
With srange
.Name = "WordPictureWatermark1"
.PictureFormat.Brightness = 0.5
.PictureFormat.Contrast = 0.5
.LockAspectRatio = True
.Height = InchesToPoints(10.47)
.Width = InchesToPoints(8.14)
.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapNone
.WrapFormat.Type = 3
.RelativeHorizontalPosition = wdRelativeVerticalPositionMargin
.RelativeVerticalPosition = wdRelativeVerticalPositionMargin
.Left = wdShapeCenter
.Top = wdShapeCenter
End With
For some reason I get Type mismatch error on the Set srange =
ActiveDocument.InLineShapes etc line?
 
A

ableone

I get "method or data member not found" at the line

.Name = "WordPictureWatermark1"
 
J

Jean-Guy Marcil

ableone said:
I am using the macro recorder to figure out how to automatically insert
a gif as a watermark. It's easy to do manually but when the resulting
macro is run, it always deletes the table and contained text that I need
in the header? That does not happen when I create the macro. Here is the
macro:

ActiveDocument.Sections(1).Range.Select
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes.AddPicture(FileName:= _
"c:\letterhead\letterhead parts\watermark.gif" _
, LinkToFile:=False, SaveWithDocument:=True).Select
Selection.ShapeRange.Name = "WordPictureWatermark1"
Selection.ShapeRange.PictureFormat.Brightness = 0.5
Selection.ShapeRange.PictureFormat.Contrast = 0.5
Selection.ShapeRange.LockAspectRatio = True
Selection.ShapeRange.Height = InchesToPoints(10.47)
Selection.ShapeRange.Width = InchesToPoints(8.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

If you are going to insert an InLineShape, use this:

Dim myrange As Range
Dim srange As InlineShape

Set myrange = Selection.Sections(1).Headers(wdHeaderFooterPrimary).Range
myrange.Collapse wdCollapseEnd

Set srange =
myrange.InlineShapes.AddPicture(FileName:="c:\letterhead\letterhead
parts\watermark.gif" _
, LinkToFile:=False, SaveWithDocument:=True, Range:=myrange)

With srange
.PictureFormat.Brightness = 0.5
.PictureFormat.Contrast = 0.5
.LockAspectRatio = True
.Height = InchesToPoints(10.47)
.Width = InchesToPoints(8.14)
End With

You cannot name an InLineShape and wrapping does not apply. But, for a
watermark, an InLineShape is not a good idea!

For a floating picture, use:

Dim srange As Shape

Set srange = ActiveDocument.Sections(1) _
.Headers(wdHeaderFooterPrimary).Shapes _
.AddPicture(FileName:="c:\letterhead\letterhead parts\watermark.gif")

With srange
.Name = "WordPictureWatermark1"
.PictureFormat.Brightness = 0.5
.PictureFormat.Contrast = 0.5
.LockAspectRatio = True
.Height = InchesToPoints(10.47)
.Width = InchesToPoints(8.14)
.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapNone
.WrapFormat.Type = 3
.RelativeHorizontalPosition = wdRelativeVerticalPositionMargin
.RelativeVerticalPosition = wdRelativeVerticalPositionMargin
.Left = wdShapeCenter
.Top = wdShapeCenter
End With
 
J

Jean-Guy Marcil

ableone said:
Woops, no it didn't...it runs, unlike the other two suggestions, but the
header table and assoc text still get overwritten.

The code I posted does not overwrite the header content.
However, I see that you use quite a large setting for the picture size
(.Height = InchesToPoints(10.47)). Since the picture is set to float over the
text, it is possible that a picture that is so large will cover up the header
content.

Make the piscture smaller...: ".Height = InchesToPoints(8)"
 
A

ableone

The code I posted does not overwrite the header content.
However, I see that you use quite a large setting for the picture size
(.Height = InchesToPoints(10.47)). Since the picture is set to float over the
text, it is possible that a picture that is so large will cover up the header
content.

Make the piscture smaller...: ".Height = InchesToPoints(8)"
OK, thanks again. This 'picture' is a full size image that needs to act
as a watermark behind all other text etc. I will look for the right
setting to make it float behind all other objects, but since I'm so weak
with Word, any clues appreciated!
 
J

Jean-Guy Marcil

ableone said:
OK, thanks again. This 'picture' is a full size image that needs to act
as a watermark behind all other text etc. I will look for the right
setting to make it float behind all other objects, but since I'm so weak
with Word, any clues appreciated!

Sorry, I should have given you the necessary code right away...

Finish the With block like this:

.Top = wdShapeCenter
.ZOrder msoSendBehindText
End With

The .ZOrder property will send the image behind the text.
 
A

ableone

Sorry, I should have given you the necessary code right away...

Finish the With block like this:

.Top = wdShapeCenter
.ZOrder msoSendBehindText
End With

The .ZOrder property will send the image behind the text.
It turns out there is another issue. That is, while it renders fine in
word 2003, it does not in word 2000. It's going to be deployed on a site
using word 2000. The issue is that the header table and it's text are
still rendered behind the full size image. Word 2003 seems to handle the
image in header differently; I can't seem to select it in quite the same
way etc. Any clues?
 
A

ableone

What I mean about selecting the image in word 2000 is complicated.

If I open the doc without header/footer showing in view, the image is
not selectable or movable immediately, but the cursor shows the image
icon in areas where there is no regular text. A right click in those
areas give me the option to view the images toolbar. But the images
toolbar has all of it's options greyed out. I can't del the image.

If I shows header/footer, I'm no longer able to select the image and the
cursor is 'normal' and no right click menu option for images.

All I need to be able to do it to have the zorder setting work, because
in word 2000 I'm back to the issue where the header table with it's text
is behind the image.
 
J

Jean-Guy Marcil

ableone said:
What I mean about selecting the image in word 2000 is complicated.

If I open the doc without header/footer showing in view, the image is

What do you mean by that? How do you do that?
not selectable or movable immediately, but the cursor shows the image
icon in areas where there is no regular text. A right click in those
areas give me the option to view the images toolbar. But the images
toolbar has all of it's options greyed out. I can't del the image.

If I shows header/footer, I'm no longer able to select the image and the
cursor is 'normal' and no right click menu option for images.

All I need to be able to do it to have the zorder setting work, because
in word 2000 I'm back to the issue where the header table with it's text
is behind the image.

I don't have Word 2000 available right now, so I can't test any of this.
But, it seems to me that all you have to do is make sure the Header/footer
is showing...
 
A

ableone

What do you mean by that? How do you do that?


I don't have Word 2000 available right now, so I can't test any of this.
But, it seems to me that all you have to do is make sure the Header/footer
is showing...
I mean the menu option view, header and footer has to be on before I
have access to header/footer. If I chose 'yes' for that, I do get into
the header, it's outline is there, but the image is not selectable etc.

Maybe I simply need to convert

.Top = wdShapeCenter
.ZOrder msoSendBehindText

to integer values, something like that?
 
A

ableone

Maybe I simply need to convert
.Top = wdShapeCenter
.ZOrder msoSendBehindText

to integer values, something like that?
That does not seem to help.

When I said the cursor changes (not in view / header and footer) I meant
the cursor has the four direction effect, as if I could move an object.
However the picture does not move if I try.

I noticed that when I insert that image manually all seems ok, it's in
the header for sure, it's selectable, cursor does not change to four
direction cursor, it's behind text etc.
 
A

ableone

One more clue...normally when viewing the doc the image in the header
area is greyed out; it loses the greyed out effect when I enter the
header area. With the end result of the word 2000 process, it's the
opposite; the image is greyed out when I enter the header and at full
color depth when viewing the doc normally (outside header area). That'd
seem to indicate that the image is not in the header...but then why
would it hide table in the header, and why isn't it selectable like a
normal image?
 
J

Jean-Guy Marcil

ableone said:
That does not seem to help.

When I said the cursor changes (not in view / header and footer) I meant
the cursor has the four direction effect, as if I could move an object.
However the picture does not move if I try.

I noticed that when I insert that image manually all seems ok, it's in
the header for sure, it's selectable, cursor does not change to four
direction cursor, it's behind text etc.

I am sorry, I do not understand what you re trying to do. You have code that
inserts an image in the header, but now you are trying to play with that
image after the code has inserted it... Why?

Also, I do not unsderstand the problem you have... If the image is in the
header, you cannot get contextual menu about images when the cursor is above
the image in the main body text area when the header is closed... But you
wrote that this is what is happening, at least, this is what I understand
from your description...

Just to be on the safe side, post the excat code you are now using.
I can test it in Word 2003, but, as I wrote earlier, not in 2000. However,
maybe someone has access to 2000 and will be able to test it.
 
A

ableone

When code is run in word 2003, the image is selectable in the header and
one can use the toolbar etc to set it's zorder. Since it's so broken in
word 2000, I'm trying to explore what the image settings are. I'm
reporting that I can't select the image, and that it seems to behave
oddly in that in some regards it seems to be in the header and in some
ways not. I'm reporting all that stuff so that someone can help me
figure out what's wrong with this in word 2000.

The code below is perfect in Word 2003.

Set srange = ActiveDocument.Sections(1) _
.Headers(wdHeaderFooterPrimary).Shapes _
.AddPicture(FileName:=strBasePath & strFileName)

With srange
.Name = "WordPictureWatermark1"
.PictureFormat.Brightness = 0.5
.PictureFormat.Contrast = 0.5
.LockAspectRatio = True
.Height = InchesToPoints(10.47)
.Width = InchesToPoints(8.14)
.WrapFormat.AllowOverlap = True
.WrapFormat.Side = wdWrapNone
.WrapFormat.Type = 3
.RelativeHorizontalPosition =
wdRelativeVerticalPositionMargin
.RelativeVerticalPosition =
wdRelativeVerticalPositionMargin
.Left = wdShapeCenter
.Top = wdShapeCenter
.IncrementLeft -43.2
.ZOrder msoSendBehindText
End With

ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
 

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