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

Re: Setting different character styles on one line of text by Jay

Jay
Tue Dec 05 21:04:25 CST 2006

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 FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Wed, 06 Dec 2006 01:06:54 +0000, Sol Apache <Sol@solapache.com>
wrote:

>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

Re: Setting different character styles on one line of text by Sol

Sol
Thu Dec 07 15:51:01 CST 2006

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


On 6/12/06 03:04, in article fgccn211no02o5hmeai3p88gm5mpokaibv@4ax.com,
"Jay Freedman" <jay.freedman@verizon.net> wrote:

> 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 FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the
> newsgroup so all may benefit.
>
> On Wed, 06 Dec 2006 01:06:54 +0000, Sol Apache <Sol@solapache.com>
> wrote:
>
>> 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