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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting page number footer on every section 1

Status
Not open for further replies.

lemonhalls

Technical User
Jun 11, 2004
52
CA
Hi,

I have a document that consists of section and page breaks. I'm using this code to insert a page number footer onto every page. But on the pages where the content of the document goes to the bottom of the page, the footer(page number) is not showing up.

Thanks in advance.
_______________________________________________________
Sub insertFooter()
Dim mySCTN As Section

For Each mySCTN In ActiveDocument.Sections
With ActiveDocument.Sections(mySCTN.Index).Footers _
(wdHeaderFooterPrimary)
.PageNumbers.Add _
PageNumberAlignment:=wdAlignPageNumberRight
End With
Next mySCTN


End Sub
 
Check on whether you have separate footers for first page, odd/even pages.

Gerry
 
This is the sub I call before I call the insertFooter sub.
I dont' understand why it is only inserted into the odd pages. I've cleared of all the code with wdSectionBreakOddPage which I had to wdSectionBreakContinuous but I'm still not getting the page number on the even pages.
______________________________

Sub mergeDoc()

'Dim activeDir As String

activeDir = InputBox _
(Prompt:="Enter the path.", Title:="Path", Default:="U:\")

With Application.FileSearch
.LookIn = activeDir 'folder with old files
End With

'move to the end of the document to insert files
Selection.EndKey Unit:=wdStory, Extend:=wdMove

With Application.FileSearch
.NewSearch
.LookIn = activeDir
.SearchSubFolders = False
.FileName = "*.doc"
.MatchTextExactly = False
If .Execute() > 0 Then

For i = 1 To .FoundFiles.Count
Selection.InsertFile FileName:=.FoundFiles(i), Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
Selection.InsertBreak Type:=wdSectionBreakNextPage
margin
Next i

'Remove Final Section Break
Selection.EndKey Unit:=wdStory
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
End Sub
 
I changed my code to this, is this the right approach?

This code turns off the the "different first page' selection.

Sub insertFooter()

Dim mySCTN As Section

For Each mySCTN In ActiveDocument.Sections

ActiveDocument.Sections(mySCTN.Index).PageSetup.DifferentFirstPageHeaderFooter = False
With ActiveDocument.Sections(mySCTN.Index)
.Footers(wdHeaderFooterPrimary).PageNumbers.Add _
PageNumberAlignment:=wdAlignPageNumberRight, _
FirstPage:=True
End With
Next mySCTN

End Sub
 
Yes, if you do not want the differences (first page, odd and even) you must turn them off.

In your earlier code where you have:

Code:
Selection.InsertBreak Type:=wdSectionBreakNextPage

add your section correction (removing first/odd/even) there. There is no real need to loop through all your sections. For what I can see of your code, you are grabbing files and appending them to the end, in new sections. So.

Code:
Selection.InsertBreak Type:=wdSectionBreakNextPage
ActiveDocument.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = False

This inserts the section break and immediately sets the different foot to False. The key is immediately, as then the index for the section is always going to be 1.

However, of course, if you have previous sections not correct, then you have to loop through to fix.

Gerry
 
thanks Gerry ;)

I changed my code to what you suggested and it works great!

S
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top