change color of a number in a numbered list?

G

ginko100

Hello everybody,

hope you are able to help me, i have spent many days trying to figure
out how to do this.

i have a numbered list like this:

1. first item <= this line is underlined
2. second item
3. third item

and want to make red the number of the line that is underlined

1[/QUOTE]. first item <= this line is underlined
2. second item
3. third item

how can i do this?
i have to loop until the end of the document, since i have many
numbered lists.

Please help me.
 
G

Graham Mayor

*How* are the lines numbered?
Word version?

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

ginko100

*How* are the lines numbered?
Word version?

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

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Hello everybody,
hope you are able to help me, i have spent many days trying to figure
out how to do this.
i have a numbered list like this:
1. first item <= this line is underlined
2. second item
3. third item
and want to make red the number of the line that is underlined
. first item <= this line is underlined
2. second item
3. third item

how can i do this?
i have to loop until the end of the document, since i have many
numbered lists.
Please help me.
[/QUOTE]

they're automatically built numbered lists...so i guess the answer to
your question is yes.
 
G

Graham Mayor

ginko100 said:
they're automatically built numbered lists...so i guess the answer to
your question is yes.

I didn't ask a question that could be answered with 'yes'? However given
autonumbering, unless you are prepared to convert the numbers to text, and
thereby lose the automatic numbering, there is no way to achieve what you
want. Converting the numbers is simple enough

Sub NumbersToText()
ActiveDocument.ConvertNumbersToText
End Sub

Thereafter it should be fairly straightforward to identify the required
number and format it.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

ginko100

I didn't ask a question that could be answered with 'yes'? However given
autonumbering, unless you are prepared to convert the numbers to text, and
thereby lose the automatic numbering, there is no way to achieve what you
want. Converting the numbers is simple enough

Sub NumbersToText()
ActiveDocument.ConvertNumbersToText
End Sub

Thereafter it should be fairly straightforward to identify the required
number and format it.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

ok thank you very much Graham Mayor
i converted the numbers to text, then i registered a macro, but it
won't work.

Sub MakeItRed()

Selection.HomeKey Unit:=wdStory 'goto beginning of doc
Selection.HomeKey Unit:=wdLine

'loop until end of file
Do Until ActiveDocument.Bookmarks("\Sel") = _
ActiveDocument.Bookmarks("\EndOfDoc")

'find carriage return in an underlined line
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute

Selection.HomeKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, count:=1, Extend:=wdExtend
Selection.Font.Color = wdColorRed

Selection.HomeKey Unit:=wdLine
Selection.movedown Unit:=wdLine, count:=1

Loop

End Sub




please help me. im stuck.
 
G

Graham Mayor

I seem to recall that you only wanted lines numbered 1 to be coloured - in
which case

Dim oRng As Range
ActiveDocument.ConvertNumbersToText
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
While .Execute(findText:="<[1]{1}.^t", _
MatchWildcards:=True, _
Wrap:=wdFindStop)
Set oRng = Selection.Range
oRng.End = oRng.End - 1
oRng.Underline = wdUnderlineSingle
oRng.Font.Color = wdColorRed
Wend
End With
End With

should work

If you want all the numbered lines coloured then adjust the findtext string
eg

While .Execute(findText:="[0-9]{1,}.^t", _
If you don't want the number underlined, remove the appropraiet line.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

ginko100

I seem to recall that you only wanted lines numbered 1 to be coloured - in
which case

Dim oRng As Range
ActiveDocument.ConvertNumbersToText
With Selection
    .HomeKey wdStory
    With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        While .Execute(findText:="<[1]{1}.^t", _
            MatchWildcards:=True, _
            Wrap:=wdFindStop)
            Set oRng = Selection.Range
            oRng.End = oRng.End - 1
            oRng.Underline = wdUnderlineSingle
            oRng.Font.Color = wdColorRed
        Wend
    End With
End With

should work

If you want all the numbered lines coloured then adjust the findtext string
eg

While .Execute(findText:="[0-9]{1,}.^t", _
If you don't want the number underlined, remove the appropraiet line.

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

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
ok thank you very much Graham Mayor
i converted the numbers  to text, then i registered a macro, but it
won't work.
Sub MakeItRed()
    Selection.HomeKey Unit:=wdStory 'goto beginning of doc
    Selection.HomeKey Unit:=wdLine
'loop until end of file
  Do Until ActiveDocument.Bookmarks("\Sel") = _
   ActiveDocument.Bookmarks("\EndOfDoc")
'find carriage return in an underlined line
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "^p"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.HomeKey Unit:=wdLine
    Selection.MoveRight Unit:=wdCharacter, count:=1, Extend:=wdExtend
    Selection.Font.Color = wdColorRed
    Selection.HomeKey Unit:=wdLine
    Selection.movedown Unit:=wdLine, count:=1
    Loop
please help me. im stuck.

thanks but i want to make red the number representing the underlined
lines only, not every number..
 
G

Graham Mayor

ginko100 said:
thanks but i want to make red the number representing the underlined
lines only, not every number..

OK that requires just a couple more lines

Dim oRng As Range
ActiveDocument.ConvertNumbersToText
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
While .Execute(findText:="[0-9]{1,}.^t", _
MatchWildcards:=True, _
Wrap:=wdFindStop)
Set oRng = Selection.Range
oRng.Paragraphs(1).Range.Select
If Selection.Font.Underline <> wdUnderlineNone Then
oRng.End = oRng.End - 1
oRng.Underline = wdUnderlineSingle
oRng.Font.Color = wdColorRed
End If
Selection.Collapse wdCollapseEnd
Wend
End With
End With

That will format the number associated with any underlined paragraph as red
and underlined.

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

ginko100

ginko100 said:
thanks but i want to make red the number representing the underlined
lines only, not every number..

OK that requires just a couple more lines

Dim oRng As Range
ActiveDocument.ConvertNumbersToText
With Selection
    .HomeKey wdStory
    With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        While .Execute(findText:="[0-9]{1,}.^t", _
            MatchWildcards:=True, _
            Wrap:=wdFindStop)
            Set oRng = Selection.Range
            oRng.Paragraphs(1).Range.Select
            If Selection.Font.Underline <> wdUnderlineNone Then
                oRng.End = oRng.End - 1
                oRng.Underline = wdUnderlineSingle
                oRng.Font.Color = wdColorRed
            End If
            Selection.Collapse wdCollapseEnd
        Wend
    End With
End With

That will format the number associated with any underlined paragraph as red
and underlined.

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

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

thank you but i get a runtime-error 5560 (invalid search string ??)
 
G

Graham Mayor

The search string is
[0-9]{1,}.^t
with the wildcard option set, which is valid for Word 2003/7
See http://www.gmayor.com/replace_using_wildcards.htm

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>


ginko100 said:
thanks but i want to make red the number representing the underlined
lines only, not every number..

OK that requires just a couple more lines

Dim oRng As Range
ActiveDocument.ConvertNumbersToText
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
While .Execute(findText:="[0-9]{1,}.^t", _
MatchWildcards:=True, _
Wrap:=wdFindStop)
Set oRng = Selection.Range
oRng.Paragraphs(1).Range.Select
If Selection.Font.Underline <> wdUnderlineNone Then
oRng.End = oRng.End - 1
oRng.Underline = wdUnderlineSingle
oRng.Font.Color = wdColorRed
End If
Selection.Collapse wdCollapseEnd
Wend
End With
End With

That will format the number associated with any underlined paragraph
as red and underlined.

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

My web sitewww.gmayor.com
Word MVP web sitehttp://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

thank you but i get a runtime-error 5560 (invalid search string ??)
 

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