Putting page numbers: 1 of xx in the footer
Author |
Message |
Glen L #1 / 4
|
 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 |
|
 |
Jay Freedma #2 / 4
|
 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 |
|
 |
Glen L #3 / 4
|
 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 |
|
 |
Jay Freedma #4 / 4
|
 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
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 |
|
|
|