Repeating Section Footer formatting

D

Dan Kelly

We have a line in our footers that can be one of a preset number of colours,
which are picked from a combobox.

At the moment that following code works, but is broken if the user uses a
Section break.

Private Sub SetColour(r, g, b)
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes("Line 3").Select
Selection.ShapeRange.Line.ForeColor.RGB = RGB(176, 209, 55)
Selection.ShapeRange.Line.ForeColor.RGB = RGB(r, g, b)
Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

I need to be able to apply the above code (or at least the Selection
formatting) to every Footer in the document.

Any pointers?
 
C

Cindy M.

Hi =?Utf-8?B?RGFuIEtlbGx5?=,

1. You have to work with the RANGE object; you can't reliably "open" multiple
headers or footers in a document and manipulate them. Word has the nasty habit
of opening a different one than you expect

2. You'd need to loop through all the sections, and test for each kind of
header or footer. Very roughly, it would look like the following. You can
probably find a better example at word.mvps.org (I think in an article about
using Find)

Dim rng as Word.Range
Dim sec as Word.Section
Dim shp as Word.Shape

For each sec in ActiveDocument.Sections
Set rng = sec.Footers(wdHeaderFooterPrimary)
Set shp = rng.ShapeRange("Line 3")
shp.ShapeRange.Line.ForeColor.RGB = RGB(176, 209, 55)
'etc.
Set rng = Nothing
Set shp = Nothing
Set rng = sec.Footers(wdHeaderFooterFirstPage)
'etc
Set rng = sec.Footers(wdHeaderFooterEvenPages)
'etc
Next
We have a line in our footers that can be one of a preset number of colours,
which are picked from a combobox.

At the moment that following code works, but is broken if the user uses a
Section break.

Private Sub SetColour(r, g, b)
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.HeaderFooter.Shapes("Line 3").Select
Selection.ShapeRange.Line.ForeColor.RGB = RGB(176, 209, 55)
Selection.ShapeRange.Line.ForeColor.RGB = RGB(r, g, b)
Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

I need to be able to apply the above code (or at least the Selection
formatting) to every Footer in the document.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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