Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2006

Tip: Looking for answers? Try searching our database.

Setting different character styles on one line of text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sol Apache - 06 Dec 2006 01:06 GMT
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
Jay Freedman - 06 Dec 2006 03:04 GMT
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.

>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
[quoted text clipped - 23 lines]
>
>Sol
Sol Apache - 07 Dec 2006 21:51 GMT
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,

> The trouble you're having is caused by applying all your insertions
> and style changes to the *entire* footer.
[quoted text clipped - 58 lines]
>>
>> Sol
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.