Setting different character styles on one line of text

S

Sol Apache

I have to put a line of text in a footer which has three different character
styles with three different sets of text. They all work on their own, but
each one cancels out the one previous to it because I do not know how to set
the styles & text properly so if I run the code all I am left with is the
third style and text.

Here is the code I am using:

ActiveDocument.Sections(1).Footers(wdheaderFooterFirstPage).Range.Style =
(³FooterBold²)
ActiveDocument.Sections(1).Footers(wdheaderFooterFirstPage).Range.Text =
³Name²
ActiveDocument.Sections(1).Footers(wdheaderFooterFirstPage).Range.Style =
(³FooterPlain²)
ActiveDocument.Sections(1).Footers(wdheaderFooterFirstPage).Range.Text =
³Address² & vbTab
ActiveDocument.Sections(1).Footers(wdheaderFooterFirstPage).Range.Font.Size
= 6
ActiveDocument.Sections(1).Footers(wdheaderFooterFirstPage).Range.Text =
³Printed on recycled paper²

How can I get all of these co-existing in the footer. The Name and Address
text sections are of varying length.


Thanks for any help

Sol
 
J

Jay Freedman

The trouble you're having is caused by applying all your insertions
and style changes to the *entire* footer.

You need to define a separate Range object, and make it correspond to
only the piece of the footer that you're currently working on. You do
this by collapsing the Range object to the end of the footer,
inserting the next piece of text, and applying the character style or
other formatting.

I think this will do what you intended:

Dim myRg As Range
Set myRg = _
ActiveDocument.Sections(1).Footers(wdHeaderFooterFirstPage).Range

With myRg
.Text = "Name" & vbTab
.Style = ("FooterBold")
.Collapse wdCollapseEnd

.Text = "Address" & vbTab
.Style = ("FooterPlain")
.Collapse wdCollapseEnd

.Text = "Printed on recycled paper"
.Font.Size = 6
End With

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
S

Sol Apache

Thank you very much, this works a dream.

I haven¹t encountered the collapse command in VB before. Usually this word
brings to mind English cricketers batting against Australia.

Thanks again

Sol
 

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