Looping in footers

R

Roderick O'Regan

I'm working in Word 2002 and Windows XP Pro SP2

I have a template which has on each page, bar the first, a coloured
logo within a table in each footer.

The following code iterates through each footer looking for the inline
picture in cell 3 of row 1 and replaces it with a monochrome version
saved as AutoText:

'Iterate through all story types in the current document
For Each kStory In ActiveDocument.StoryRanges
'Iterate through all linked stories
Do
On Error Resume Next
Select Case kStory.StoryType
Case wdPrimaryFooterStory, wdEvenPagesFooterStory,
wdFirstPageFooterStory
'first deletes the coloured logo in the footers
If kStory.Tables.Count > 0 Then
kStory.Tables(1).Cell(1, 3).Range.Delete
'inserts the B&W logo in the footers
Set myRange = kStory.Tables(1).Cell(1, 3).Range
myRange.Collapse Direction:=wdCollapseStart
ActiveDocument.AttachedTemplate.AutoTextEntries(" Mono logo").Insert
_
Where:=myRange, RichText:=True
Exit Sub
End If

Case Else
'Do Nothing
End Select
On Error GoTo 0
'Get next linked story (if any)
Set kStory = kStory.NextStoryRange
Loop Until kStory Is Nothing
Next
'go back to the top of the document
Set myRange = Nothing
Set kStory = Nothing
ActiveDocument.Bookmarks("\StartofDoc").Select

All of this works perfectly provided it is in portrait orientation.
However, if I now insert a landscape page in the middle of the
document somewhere and remove the "Link to Previous" on the footers
from that point forward the logo only changes up to to the landscape
page and then ignores the rest.

I can see that it might have something to do with my stories
especially as they are now unlinked.

Could anyone suggest, please, a way of going to every footer of each
section irrespective of the footer linked status and then being able
to change that logo?

Roderick
 
F

fumei via OfficeKB.com

If you are only trying to perform action with footers, then you really do not
need to use StoryRanges. Why look in the Footnote story, or the MainStroy,
or the EndNotes story yadda yadda, if you only want to action in the footers?

If you are indeed trying to a replace everywhere, then sure, use StoryRanges
to get everywhere.

But if you are not trying to replace/action everywhere, why not just action
where you DO? Using StoryRanges where not needed seems excessive, and
pointless, to me.

Your post is not quite consistent though. You state: "I have a template
which has on each page, bar the first, a coloured logo within a table in each
footer."

Bar the first. Yet your code has:

Case wdPrimaryFooterStory, wdEvenPagesFooterStory,
wdFirstPageFooterStory

Oh...never mind, I see that you are adding an extra test with the table count.
No need, no need.

If each SECTION has its first page with no log - INCLUDING the landscape one -
then simply action the footers that are NOT FirstPage.

Dim r As Range
Dim oSection As Section
For Each oSection In ActiveDocument.Sections
' delete the cell content
Set r = oSection.Footers(wdHeaderFooterPrimary) _
.Range.Tables(1).Cell(1, 3).Range
r.Delete
' insert the AutoText
ActiveDocument.AttachedTemplate.AutoTextEntries(" Mono logo") _
.Insert Where:=r, _
RichText:=True
Next

The above will work for changes between portrait and landscape. The real
issues are:

1. whether you are using DifferentFirstPage for all sections, or not.
2. whether you are using OddEven for any sections
3. what is the status of LinkToPrevious?

ALL of these are fairly easily dealt with. You just have to know what they
are To action them is straightforward logic.

IF your situation is:

1. DifferentFirstPage for the first Section
2. No DifferentFirstPage (or DifferentOddEven) for all the other sections.

the above code will work, as is.

NOTE: the code does not do anything with the placement of the footer in the
landscape section. It assumes you have placed it properly. It only deals
with the content of that cell. It removes its contwent, and inserts the
Autotext.

As it stand, it does not matter if LinkToPrevious is true, or False. The
code removes the content of the cell, and inserts the AutoText.

That's it.
 
R

Roderick O'Regan

Thanks fumei for your advice. The point is well taken.

And, as you rightly said, it worked perfectly. I'm not using
DifferentFirstPage for any of my subsequent sections.

Thank you also, Jay, for your advice.

Roderick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top