When I position a floating object (such as a text box or graphic) “Relative to Page” in Word 2000, it doesn’t end up where it should – why doesn’t it?
Article contributed by Dave Rado
Word 2000 can be a nightmare when it comes to positioning shapes – Word 97 was much more predictable.
The problem in Word 2000 is that:
- Anchors can be within a table
- If the anchor is within a table you can't position the shape relative to the page (if you select that option, it gets positioned relative to the table instead!)
- Anchors in Word 2000 have a way of jumping into tables when you're looking the other way, and then laughing at you while you try to figure out what happened!
For more on anchors see: Working with Anchors.
So if you're positioning shapes manually, lock the anchor to a paragraph that is not in a table before you start. If you're doing it in code, anchor the shape to a paragraph that is not in a table, and lock the anchor.
If you want a shape (such as a line, text box or graphic) to appear on every page, you should put it in the Header and set it to be “behind text”. The final paragraph in the Header cannot be in a table, so it makes sense to anchor it to that paragraph
Here's an example of how to do it with code (you could use the same principle for watermarks). This code inserts two lines in the primary Header of the first section of the document:
Sub AddLinesToHeader()
Dim oHeader As HeaderFooter,
MyRange As Range, oLine
As Shape
System.Cursor = wdCursorWait
Set oHeader =
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary)
'Make sure the shape anchored to the final paragraph in
the Header
Set MyRange =
oHeader.Range.Paragraphs.Last.Range
Set oLine = oHeader.Shapes.AddLine(0, 0, 0, 0,
Anchor:=MyRange)
With oLine
.RelativeHorizontalPosition =
wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Width = CentimetersToPoints(1)
.Left = CentimetersToPoints(0.5)
.Top = CentimetersToPoints(21.76)
.LockAnchor = True
.WrapFormat.Type = wdWrapNone
'It's a good idea to name shapes you
add, so that if you want to hide them,
'or whatever later, you can refer to them by name
.Name = "First Line"
'Add any other parameters you need,
eg .Line.Weight = etc
End With
Set oLine = oHeader.Shapes.AddLine(0, 0, 0, 0,
Anchor:=MyRange)
With oLine
.RelativeHorizontalPosition =
wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Width = CentimetersToPoints(1)
.Left = CentimetersToPoints(0.5)
.Top = CentimetersToPoints(22.08)
.LockAnchor = True
.WrapFormat.Type = wdWrapNone
.Name = "Second Line"
'add other parameters you need, eg .Line.Weight
= etc
End With
System.Cursor = wdCursorNormal
End Sub