Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Page Numbering in New Sections 1

Status
Not open for further replies.

bigrho

MIS
Aug 4, 2003
1
US
I need help inserting a new section with page numbering when using the range object to create the section (the new section may not be the active section). I am able to add the page number if I know the section number. However, the user could add additional sections into the document, which means I can not hard code the section number.
 
Instead of trying to enter the page number simply insert the pagenumber field code and this should automatically recalculate for you

Use code such as:
'To add a Section number
Selection.fields.add Range:=Selection.Range, Type:=wdFieldEmpty, Text:="SECTION", PreserveFormatting:=True

'To add a SectionPage number
'as above but:
Text:="SECTIONPAGES"

'To add PageNumbers
'as above but:
Text:="PAGE"

Hope this helps

Asjeff
 
Hi bigrho,

You might need to experiment with this a little to get it right but if, before you insert, you get the index of the section where you are about to insert you ought to be able to work with the one you then insert because it will be the next one in the document, something like ..

Code:
Dim tjDoc As Document
Dim tjRange As Range
Dim tjSectIndex As Integer

Set tjDoc = ActiveDocument         ' Or your document
Set tjRange = tjDoc.Range(28, 28)  ' Your Range

tjSectIndex = tjRange.Sections(tjRange.Sections.Count).Index

tjRange.InsertBreak Type:=wdSectionBreakNextPage

MsgBox "I have just inserted Section with Index number " & tjSectIndex + 1

Enjoy,
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top