
Mixing tabs, fields, text in a header
Hi Gary,
Working with Collapse in ranges in headers is not that much fun as you have noticed. ;-)
Try some code like this:
---------------------------------------------------
Dim oRange As Range
Dim oHeader As HeaderFooter
Set oHeader = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary)
Set oRange = oHeader.Range
ActiveDocument.Fields.Add Range:=oRange, Type:=wdFieldPage
With oRange
.InsertAfter vbTab & "My text"
End With
Set oRange = Nothing
Set oHeader = Nothing
---------------------------------------------------
Hope this helps,
regards,
Astrid
So that all can benefit from the discussion, please post all follow-ups to the newsgroup.
Visit the MVP Word FAQ site at http://www.mvps.org/word/
Quote:
> I'm having trouble with customizing a header, which can print either
> as centered text & right-justified page number (which works fine) or
> as centered page number and right-justified text (which doesn't).
> I add the tabs just fine. And in the case of a right-justified page
> number, this code works fine:
> with hdr.range
> .Text = vbTab & runHeadText & vbTab
> .Collapse wdCollapseEnd
> .Fields.Add range:=hdr.range, Type:=wdFieldPage
> end with
> The problem is that I don't know how to do the equivalent and add text
> after the page number field. When I try to add text using InsertAfter,
> the text ends up in front of the field:
> with hdr.range
> .Text = vbTab
> .Collapse wdCollapseEnd
> .Fields.Add range:=hdr.range, Type:=wdFieldPage
> .Collapse wdCollapseEnd
> .InsertAfter vbTab & runHeadText
> end with
> Obviously, I'm missing some concept here about mixing fields with text
> in a range. Can someone clue me in?
> thanks in advance,
> gary