Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-16-2014, 04:16 PM
Irrma Irrma is offline What's wrong with my loop? Windows 7 64bit What's wrong with my loop? Office 2010 64bit
Novice
What's wrong with my loop?
 
Join Date: Jun 2014
Posts: 2
Irrma is on a distinguished road
Default What's wrong with my loop?

Hi,

I am getting multiple footers in sections. Does anybody know what I am going wrong?

Sub AddFooter()
'
' AddFooter Macro
'
'
Dim i As Integer


ActiveDocument.PageSetup.OddAndEvenPagesHeaderFoot er = True
For i = 1 To ActiveDocument.Sections.Count

ActiveDocument.Sections(i).Footers(wdHeaderFooterP rimary).Range _
.InsertAfter "Odd Header"
ActiveDocument.Sections(i).Footers(wdHeaderFooterE venPages).Range _
.InsertAfter "Even Header"


Next i

End Sub

Please help.Thank you!!!
Reply With Quote
  #2  
Old 06-16-2014, 05:02 PM
gmaxey gmaxey is offline What's wrong with my loop? Windows 7 32bit What's wrong with my loop? Office 2010 (Version 14.0)
Word MVP 2003-2009
 
Join Date: May 2010
Location: Marble, NC
Posts: 1,133
gmaxey has a spectacular aura aboutgmaxey has a spectacular aura aboutgmaxey has a spectacular aura about
Default

There is nothing wrong with your loop as it is doing exactly what you are telling it to do.

Word headers and footers are sort of like the old player piano sheets that form a continuous loop that repeats over an over again. Unless you break the link between new sections when you add them the contents will just keep piling up. Unless broken the first section header is sort of linked to the last section header.

Code:
Sub AddFooter()
Dim i As Integer
ActiveDocument.PageSetup.OddAndEvenPagesHeaderFooter = True
For i = 1 To ActiveDocument.Sections.Count
  ActiveDocument.Sections(i).Footers(wdHeaderFooterPrimary).LinkToPrevious = False
  ActiveDocument.Sections(i).Footers(wdHeaderFooterPrimary).Range.InsertAfter "Odd Footer Section " & i
  ActiveDocument.Sections(i).Footers(wdHeaderFooterEvenPages).LinkToPrevious = False
  ActiveDocument.Sections(i).Footers(wdHeaderFooterEvenPages).Range.InsertAfter "Even Footer Section " & i
Next i
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 06-17-2014, 06:25 AM
Irrma Irrma is offline What's wrong with my loop? Windows 7 64bit What's wrong with my loop? Office 2010 64bit
Novice
What's wrong with my loop?
 
Join Date: Jun 2014
Posts: 2
Irrma is on a distinguished road
Default Still not working

Thank you very much gmaxey... It is still not doing what I want. It is still adding multiple footers to sections...
My last footer (last section) looks like this:

Even Footer Section 3Even Footer Section 4Even Footer Section 5Even Footer Section 6Even Footer Section 7Even Footer Section 8Even Footer Section 9Even Footer Section 10Even Footer Section 11Even Footer Section

I am sure my script has a flaw but I can't find it . Please help!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
First 5 slides in a loop Joop PowerPoint 0 05-06-2014 09:30 AM
What's wrong with my loop? End or alter a loop? DJSOUND Word VBA 1 10-11-2013 08:11 PM
What's wrong with my loop? How to a For loop in VBA Jennifer Murphy Word VBA 1 01-29-2013 03:30 AM
While loop not working right Cbrehm Excel Programming 0 05-11-2011 11:05 AM
What's wrong with my loop? Continuous Loop cksm4 Word 6 01-06-2011 09:03 PM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 07:30 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2020 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft