Mixing tabs, fields, text in a header 
Author Message
 Mixing tabs, fields, text in a header

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



Fri, 15 Apr 2005 23:57:35 GMT  
 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



Sun, 24 Apr 2005 01:14:52 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Formatting mixed text/fields in a report

2. Mixing Text w/ Numeric Fields

3. Entering Page fields mixed with text

4. Text field limited to 256 characters in report section header after running text through filter function

5. mixing integer and text in a text box

6. OE headers all mixed up.

7. Header problem with mixed orientation

8. Memo/Text field will not update in Access97 memo field linked to SQL7.0 text field

9. Text fields in page headers and footers

10. Referencing a form text field in header.


 
Powered by phpBB® Forum Software © phpBB Group