Different fonts in footer when using "Footers(wdHeaderFooterFirstPage).Range" - XP SP3, Word 2003 SP

I

Ian B

Hi
I wrote a routine many years ago which has worked fine.
I now have to insert another string in the footer using a different font
size.
I've experimented for hours but my footer always ends up with all footer
text at 16 pts.
The documents are very large with up to 30 sections so to actually
manipulate the footers by opening them and inserting required text is
unacceptably slow..
See my attempts below:
I think I need to introduce a selection into the footer, but the footers(xx)
works only with a range and that range seems to be the whole footer.

I think I'm "dead in the water", but any help much appreciated.

Cheers

Ian B
~~~~~~~~~~~~~~
With ActiveDocument.Sections(lS).Footers(wdHeaderFooterFirstPage).Range
.Paragraphs.TabStops.ClearAll
.Font.Size = 8
.ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(17),
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces
.InsertAfter Text:=sPath & vbTab & "_________Initials" & vbCrLf
End With

With ActiveDocument.Sections(lS).Footers(wdHeaderFooterPrimary).Range
.Font.Size = 16
Selection.InsertAfter Text:=sInsertString
End With
 
I

Ian B

Sorry, my cut & paste was not that great, the second "with" should be
"wdHeaderFooterFirstPage"
 
G

Graham Mayor

It is simply a matter of setting the ranges accurately to reflect what you
want to do e.g. to add some 16 point text to an existing First Page header
in Section 1 without changing the content of the header

Dim oHeader As HeaderFooter
Dim oRng As Range
Set oHeader = ActiveDocument.Sections(1) _
..Headers(wdHeaderFooterFirstPage)
Set oRng = oHeader.Range
With oRng
.InsertAfter vbCr
.Start = oHeader.Range.End
.Text = "This is the additional text"
.End = oHeader.Range.End
.Font.Size = 16
.Fields.Update
End With

To add the text after all headers

Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oRng As Range
For Each oSection In ActiveDocument.Sections
For Each oHeader In oSection.Headers
Set oRng = oHeader.Range
With oRng
If Len(oRng) > 1 Then
.InsertAfter vbCr
End If
.Start = oHeader.Range.End
.Text = "This is the additional text"
.End = oHeader.Range.End
.Font.Size = 16
.Fields.Update
End With
Next oHeader
Next oSection


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
F

Fumei2 via OfficeKB.com

OR.....

If you use Styles fully;

Sub AddText2Footer()
With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
.Range.Text = .Range.Text & "Additional text."
.Range.Paragraphs(.Range.Paragraphs.Count).Style = "AdditionalFooter"
End With
End Sub

This takes the original footer text content (which MUST terminate with a
paragraph mark), appends the text "Additional text.", then applies the style
"AdditionalText" to the LAST paragraph in the range (i.e. the newly added
paragraph).

Assuming of course the additional text is indeed being added to the end. If
it is not, then yes you have to work within the range.

Gerry
Graham said:
It is simply a matter of setting the ranges accurately to reflect what you
want to do e.g. to add some 16 point text to an existing First Page header
in Section 1 without changing the content of the header

Dim oHeader As HeaderFooter
Dim oRng As Range
Set oHeader = ActiveDocument.Sections(1) _
.Headers(wdHeaderFooterFirstPage)
Set oRng = oHeader.Range
With oRng
.InsertAfter vbCr
.Start = oHeader.Range.End
.Text = "This is the additional text"
.End = oHeader.Range.End
.Font.Size = 16
.Fields.Update
End With

To add the text after all headers

Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oRng As Range
For Each oSection In ActiveDocument.Sections
For Each oHeader In oSection.Headers
Set oRng = oHeader.Range
With oRng
If Len(oRng) > 1 Then
.InsertAfter vbCr
End If
.Start = oHeader.Range.End
.Text = "This is the additional text"
.End = oHeader.Range.End
.Font.Size = 16
.Fields.Update
End With
Next oHeader
Next oSection
Hi
I wrote a routine many years ago which has worked fine.
[quoted text clipped - 28 lines]
Selection.InsertAfter Text:=sInsertString
End With
 
F

Fumei2 via OfficeKB.com

Whooops, I meant:

With ActiveDocument.Sections(1).Footers(wdHeaderFooterFirstPage)

Gerry
OR.....

If you use Styles fully;

Sub AddText2Footer()
With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
.Range.Text = .Range.Text & "Additional text."
.Range.Paragraphs(.Range.Paragraphs.Count).Style = "AdditionalFooter"
End With
End Sub

This takes the original footer text content (which MUST terminate with a
paragraph mark), appends the text "Additional text.", then applies the style
"AdditionalText" to the LAST paragraph in the range (i.e. the newly added
paragraph).

Assuming of course the additional text is indeed being added to the end. If
it is not, then yes you have to work within the range.

Gerry
It is simply a matter of setting the ranges accurately to reflect what you
want to do e.g. to add some 16 point text to an existing First Page header
[quoted text clipped - 40 lines]
 
I

Ian B

Thanks Graham
Ranges are one of my weak points, but I have it working now.
Again, thanks!

Ian B
 

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

Similar Threads


Top