Nelviticus
Programmer
I need to place a shape at the end of a header (which usually but not always contains a table) using VBA. I can define objects for my shape and header and a range in which to place it, like this:
However, the only way I can find of moving the shape to the end of the header is by moving the selection into the header then cutting and pasting like this:
That's a horrible way to do it, for lots of reasons, not the least of which is that the clipboard will contain a copy of the shape.
Is there any way to do this properly? How do I find the range right at the end of the header? The code won't know in advance whether the header contains tables, text, or nothing.
Thanks in advance!
Nelviticus
Code:
' The header where we want to place the shape
Set oHeader = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary)
' The range is used as the anchor point for the shape
Set rRange = oHeader.Range.Paragraphs.Last.Range
' Place the shape
Set oShape = oHeader.Shapes.AddTextEffect(msoTextEffect2, tText, "Arial Black", 72#, _
msoFalse, msoFalse, 163.25, 60.25, rRange)
However, the only way I can find of moving the shape to the end of the header is by moving the selection into the header then cutting and pasting like this:
Code:
' Move the shape to the end of the header, otherwise it won't be
' centred properly (Can't get the Range of this point for some reason)
With Selection
.HeaderFooter.Shapes(oShape.Name).Select
.Cut
.EndKey Unit:=wdStory
.Paste
End With
That's a horrible way to do it, for lots of reasons, not the least of which is that the clipboard will contain a copy of the shape.
Is there any way to do this properly? How do I find the range right at the end of the header? The code won't know in advance whether the header contains tables, text, or nothing.
Thanks in advance!
Nelviticus