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 / Long Documents / November 2005

Tip: Looking for answers? Try searching our database.

Replacing style of the first word of a paragraph only

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
homeologica - 21 Nov 2005 03:10 GMT
In a document I must convert only the first word, (entry), of a paragraph.
This first word have a specific font different to rest of the paragraph.

Can I do this?

Thanks.

Alejandro Fernandez
Greg Maxey - 21 Nov 2005 03:20 GMT
Doesn't change the style, but does change the font of the first word.

Sub Test()
Dim oPar
For Each oPar In ActiveDocument.Paragraphs
 oPar.Range.Words.First.Font.Name = "Courier New"
Next
End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> In a document I must convert only the first word, (entry), of a
> paragraph. This first word have a specific font different to rest of
[quoted text clipped - 5 lines]
>
> Alejandro Fernandez
homeologica - 21 Nov 2005 03:33 GMT
Thanks Greg. I need to change the style because headings must have StyleRef
DefinedStyle. Only First words must appear in this Headings
Greg Maxey - 21 Nov 2005 03:50 GMT
Try:

Sub Test()
Dim oPar
For Each oPar In ActiveDocument.Paragraphs
 oPar.Range.Words.First.Select
 Selection.Style = ActiveDocument.Styles("Heading 1 Char")
Next
End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Thanks Greg. I need to change the style because headings must have
> StyleRef DefinedStyle. Only First words must appear in this Headings
homeologica - 21 Nov 2005 04:43 GMT
Greg.

I am trying some modifications in your code. I think this is very close to
the real solution.

Many thanks.

Alejandro Fernandez
homeologica - 21 Nov 2005 06:07 GMT
Greg
I need to select the first word of each paragraph which be a word formattaed
as Tahoma 11 points font . Not other first words. This code converts to new
style paragraph marks too. I must avoid this.

So, the statement

oPar.Range.Words.First.Select

Must be changed or validated

Thank you for your valuable help.

Alejandro Fernandez
Greg Maxey - 21 Nov 2005 10:59 GMT
Try:
Sub Test()
Dim oPar
For Each oPar In ActiveDocument.Paragraphs
 oPar.Range.Words.First.Select
 Selection.MoveEnd wdCharacter, -1
 With Selection
   If .Font.Name = "Tahoma" And .Font.Size = "11" Then
     .Style = ActiveDocument.Styles("Heading 1")
   End If
 End With
Next
End Sub

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Greg
> I need to select the first word of each paragraph which be a word
[quoted text clipped - 12 lines]
>
> Alejandro Fernandez
Daiya Mitchell - 21 Nov 2005 13:15 GMT
Sideways approach--test on a COPY of the doc.

Assuming what you want to change is the only stuff formatted in Tahoma 11pt,
use Find and Replace?

Find: an empty box, click More, then Format in the F&R dialog, Font to
format the empty box as 11pt Tahoma

Replace: an empty box, click Format in the F&R dialog, Style to format the
empty box as desired style.

> In a document I must convert only the first word, (entry), of a paragraph.
> This first word have a specific font different to rest of the paragraph.
[quoted text clipped - 4 lines]
>
> Alejandro Fernandez

Signature

Daiya Mitchell, MVP Mac/Word
Word FAQ: http://www.word.mvps.org/
MacWord Tips: <http://www.word.mvps.org/MacWordNew/>
What's an MVP? A volunteer! Read the FAQ: http://mvp.support.microsoft.com/

homeologica - 21 Nov 2005 17:12 GMT
Thanks Daiya:

Your procedure format all paragraph instead the first word (Tahoma 11pt)

This word must appear in each page heading.

Alejandro Fernandez
Daiya Mitchell - 21 Nov 2005 17:48 GMT
Hi Alejandro,

You did say that the word you need to apply the style to already has a
different font from the rest, right?  Because that should work, if those
words are the only ones formatted in that font--I hadn't tested it before
but I just did and it works here (MacWord 2004).

However, in the Replace box, the style you choose *must* be a character
style (denoted by underscored "a"), not a paragraph style (denoted by ¶ in
the list in the Style dialog).

If you use a paragraph style for the Replace setting, then the entire
paragraph does change.  But it works if you use a character style, and a
character style is what you want for dictionary-style headings anyhow.

Is your DefinedStyle a paragraph or a character style?

> Thanks Daiya:
>
[quoted text clipped - 3 lines]
>
> Alejandro Fernandez

Signature

Daiya Mitchell, MVP Mac/Word
Word FAQ: http://www.word.mvps.org/
MacWord Tips: <http://www.word.mvps.org/MacWordNew/>
What's an MVP? A volunteer! Read the FAQ: http://mvp.support.microsoft.com/

homeologica - 21 Nov 2005 19:16 GMT
Yes Daiya, you're right. Character style works fine.

Thanks a lot. Thanks to Greg too.

Alejandro Fernandez

Rate this thread:






 
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.