Putting page numbers: 1 of xx in the footer 
Author Message
 Putting page numbers: 1 of xx in the footer

Hello everyone.

I have code working that lists the page number in the footer:

Dim rngFooter As Range
Set rngFooter = .Sections(1).Footers(wdHeaderFooterPrimary).Range
rngFooter.Text = "some text that I want in the footer" & vbTab &
rngFooter.Collapse wdCollapseEnd
rngFooter.Fields.Add Range:=rngFooter, Type:=wdFieldPage

However, I need to show the total number of pages, too:

e.g.  need   1 of 10, 2 of 10, 3 of 10 to show in the footer of pages
1,2,3

instead of just 1,2,3 showing in the footer on pages 1,2,3

There is a field wdFieldNumPages that I can add to the footer, but I
can't figure out how to get the string: " of " to be printed between
the wdFieldPage and the wdFieldNumPages fields.

If I also add the wdFieldNumPages to the footer, it always overwrites
the string " of " and I'm left with 110, 210, 310, on pages 1,2,3
instead of 1 of 10, 2 of 10, 3 of 10.

Any help appreciated.

Thank you,   Glen



Sun, 21 Mar 2004 08:47:20 GMT  
 Putting page numbers: 1 of xx in the footer
Hi, Glen,

Make sure you collapse the range to its end and move one character to the
right after each addition to the text in the footer. For example,

  Dim rngFooter As Range
  Set rngFooter = ActiveDocument.Sections(1). _
      Footers(wdHeaderFooterPrimary).Range
  With rngFooter
    .Text = "some text that I want in the footer" & vbTab
    .Collapse wdCollapseEnd
    .Move unit:=wdCharacter, Count:=1
    .Fields.Add Range:=rngFooter, Type:=wdFieldPage
    .Collapse wdCollapseEnd
    .Move unit:=wdCharacter, Count:=1
    .Text = " of "
    .Collapse wdCollapseEnd
    .Move unit:=wdCharacter, Count:=1
    .Fields.Add Range:=rngFooter, Type:=wdFieldNumPages
  End With

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word


Quote:
> Hello everyone.

> I have code working that lists the page number in the footer:

> Dim rngFooter As Range
> Set rngFooter = .Sections(1).Footers(wdHeaderFooterPrimary).Range
> rngFooter.Text = "some text that I want in the footer" & vbTab &
> rngFooter.Collapse wdCollapseEnd
> rngFooter.Fields.Add Range:=rngFooter, Type:=wdFieldPage

> However, I need to show the total number of pages, too:

> e.g.  need   1 of 10, 2 of 10, 3 of 10 to show in the footer of pages
> 1,2,3

> instead of just 1,2,3 showing in the footer on pages 1,2,3

> There is a field wdFieldNumPages that I can add to the footer, but I
> can't figure out how to get the string: " of " to be printed between
> the wdFieldPage and the wdFieldNumPages fields.

> If I also add the wdFieldNumPages to the footer, it always overwrites
> the string " of " and I'm left with 110, 210, 310, on pages 1,2,3
> instead of 1 of 10, 2 of 10, 3 of 10.

> Any help appreciated.

> Thank you,   Glen



Sun, 21 Mar 2004 09:51:05 GMT  
 Putting page numbers: 1 of xx in the footer
Hi Jay.

Your code worked great, thanks very much.

One follow up question... is there anyway for me to move the "1 of 2"
to the right several spaces in the footer?

If I insert another vbtab the page numbers move to the next line of
the footer
which I don't want.

If I try this code:  ".Move unit:=wdCharacter, Count:=6"   before
inserting the wdFieldPage, nothing happens (the field is not moved to
the right 6 spaces).

Thank you,
Glen

Quote:

> Hi, Glen,

> Make sure you collapse the range to its end and move one character to the
> right after each addition to the text in the footer. For example,

>   Dim rngFooter As Range
>   Set rngFooter = ActiveDocument.Sections(1). _
>       Footers(wdHeaderFooterPrimary).Range
>   With rngFooter
>     .Text = "some text that I want in the footer" & vbTab
>     .Collapse wdCollapseEnd
>     .Move unit:=wdCharacter, Count:=1
>     .Fields.Add Range:=rngFooter, Type:=wdFieldPage
>     .Collapse wdCollapseEnd
>     .Move unit:=wdCharacter, Count:=1
>     .Text = " of "
>     .Collapse wdCollapseEnd
>     .Move unit:=wdCharacter, Count:=1
>     .Fields.Add Range:=rngFooter, Type:=wdFieldNumPages
>   End With

> --
> Regards,
> Jay Freedman
> Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word



> > Hello everyone.

> > I have code working that lists the page number in the footer:

> > Dim rngFooter As Range
> > Set rngFooter = .Sections(1).Footers(wdHeaderFooterPrimary).Range
> > rngFooter.Text = "some text that I want in the footer" & vbTab &
> > rngFooter.Collapse wdCollapseEnd
> > rngFooter.Fields.Add Range:=rngFooter, Type:=wdFieldPage

> > However, I need to show the total number of pages, too:

> > e.g.  need   1 of 10, 2 of 10, 3 of 10 to show in the footer of pages
> > 1,2,3

> > instead of just 1,2,3 showing in the footer on pages 1,2,3

> > There is a field wdFieldNumPages that I can add to the footer, but I
> > can't figure out how to get the string: " of " to be printed between
> > the wdFieldPage and the wdFieldNumPages fields.

> > If I also add the wdFieldNumPages to the footer, it always overwrites
> > the string " of " and I'm left with 110, 210, 310, on pages 1,2,3
> > instead of 1 of 10, 2 of 10, 3 of 10.

> > Any help appreciated.

> > Thank you,   Glen



Tue, 23 Mar 2004 02:38:37 GMT  
 Putting page numbers: 1 of xx in the footer
Hi, Glen,

The simple, quick'n'dirty method is just to tack on some spaces after the
vbTab,

   .Text = "some text that I want in the footer" & vbTab & "      "

The real, permanent solution is, instead, to change the position of the tab
stop in the footer style. Go to Format/Style, select the Footer style, and
click Modify. Check the box for Add to Template (and be sure to clear the
box for Automatic Update!). Click the Format button and select Tabs from the
popup. In the Tabs dialog, change the position of the 3" tab to a slightly
larger value, such as 3.5". OK out to the document.

By the way, the reason your .Move didn't work is that it's trying to move
the range, but at that time there are no more characters to the right of the
range's current position. It's like trying to move the cursor with the right
arrow key when it's already at the end of the document.

--
Regards,
Jay Freedman
Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word


Quote:
> Hi Jay.

> Your code worked great, thanks very much.

> One follow up question... is there anyway for me to move the "1 of 2"
> to the right several spaces in the footer?

> If I insert another vbtab the page numbers move to the next line of
> the footer
> which I don't want.

> If I try this code:  ".Move unit:=wdCharacter, Count:=6"   before
> inserting the wdFieldPage, nothing happens (the field is not moved to
> the right 6 spaces).

> Thank you,
> Glen




- Show quoted text -

Quote:
> > Hi, Glen,

> > Make sure you collapse the range to its end and move one character to
the
> > right after each addition to the text in the footer. For example,

> >   Dim rngFooter As Range
> >   Set rngFooter = ActiveDocument.Sections(1). _
> >       Footers(wdHeaderFooterPrimary).Range
> >   With rngFooter
> >     .Text = "some text that I want in the footer" & vbTab
> >     .Collapse wdCollapseEnd
> >     .Move unit:=wdCharacter, Count:=1
> >     .Fields.Add Range:=rngFooter, Type:=wdFieldPage
> >     .Collapse wdCollapseEnd
> >     .Move unit:=wdCharacter, Count:=1
> >     .Text = " of "
> >     .Collapse wdCollapseEnd
> >     .Move unit:=wdCharacter, Count:=1
> >     .Fields.Add Range:=rngFooter, Type:=wdFieldNumPages
> >   End With

> > --
> > Regards,
> > Jay Freedman
> > Microsoft Word MVP        Word MVP FAQ site: http://www.mvps.org/word



> > > Hello everyone.

> > > I have code working that lists the page number in the footer:

> > > Dim rngFooter As Range
> > > Set rngFooter = .Sections(1).Footers(wdHeaderFooterPrimary).Range
> > > rngFooter.Text = "some text that I want in the footer" & vbTab &
> > > rngFooter.Collapse wdCollapseEnd
> > > rngFooter.Fields.Add Range:=rngFooter, Type:=wdFieldPage

> > > However, I need to show the total number of pages, too:

> > > e.g.  need   1 of 10, 2 of 10, 3 of 10 to show in the footer of pages
> > > 1,2,3

> > > instead of just 1,2,3 showing in the footer on pages 1,2,3

> > > There is a field wdFieldNumPages that I can add to the footer, but I
> > > can't figure out how to get the string: " of " to be printed between
> > > the wdFieldPage and the wdFieldNumPages fields.

> > > If I also add the wdFieldNumPages to the footer, it always overwrites
> > > the string " of " and I'm left with 110, 210, 310, on pages 1,2,3
> > > instead of 1 of 10, 2 of 10, 3 of 10.

> > > Any help appreciated.

> > > Thank you,   Glen



Tue, 23 Mar 2004 04:07:25 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Adding Total Number of slides to the page number field in the footer

2. Word not printing total number of pages in page footer correctly

3. putting section number into footer via code

4. Inserting page numbers in footer with word automation

5. Page Numbering in Footer

6. HIGHEDIT & RTF page numbers in footer

7. Table Footer/ Page Footer

8. Page footer and Group footer

9. Page Footer on Page 1 Refers to Page 2

10. Print report page footer last page only?

11. cycle footers page by page

12. Update 2nd page Footer w/o 2nd page

 

 
Powered by phpBB® Forum Software