Bold every second line

K

Kanga 85

I have a long list, and would like to bold every second line of the whole
document. I need a macro because new entries will be inserted at various
points and so muck up any original formatting.

Thanks in advance,
 
G

Graham Mayor

Assuming each 'line' is a paragraph then

Dim orng As Range
Dim i As Long
Set orng = ActiveDocument.Range
For i = 1 To orng.Paragraphs.Count
If i Mod 2 = 0 Then
orng.Paragraphs(i).Range.Bold = True
Else
orng.Paragraphs(i).Range.Bold = False
End If
Next i

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
K

Kanga 85

Thanks Graham,
I actually want lines rather than paragraphs, but I should be able to modify
your macro (or my docu,ment).
 
M

macropod

Hi Kanga 85,

Lines are a very fluid concept in Word.

Obviously, editing a line can chnge which words appear on that line and all subsequent lines. Plus they're even liable to change if
you switch printers. Formatting changes (eg font, margins, apge size can likewise affect what constitutes a line. Unless you're
using paragraph marks or line-feed characters, it can become challenging to apply the formatting to the correct 'lines'.
 
M

macropod

Hi Kanga,

In case you've got line-feeds at the end of each logical line, try something along the lines of:

Sub LineFormatter()
Dim oRng As Range
Dim i As Long
With ActiveDocument
With .Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^l"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
For i = 1 To .Paragraphs.Count
If i Mod 2 = 0 Then
.Paragraphs(i).Range.Bold = True
Else
.Paragraphs(i).Range.Bold = False
End If
Next i
With .Content.Find
.Text = "^p"
.Replacement.Text = "^l"
.Execute Replace:=wdReplaceAll
.Text = "^l^p"
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
End With
End Sub
 
K

Kanga 85

Thanks Macropod,
Very helpful

macropod said:
Hi Kanga,

In case you've got line-feeds at the end of each logical line, try something along the lines of:

Sub LineFormatter()
Dim oRng As Range
Dim i As Long
With ActiveDocument
With .Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^l"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
For i = 1 To .Paragraphs.Count
If i Mod 2 = 0 Then
.Paragraphs(i).Range.Bold = True
Else
.Paragraphs(i).Range.Bold = False
End If
Next i
With .Content.Find
.Text = "^p"
.Replacement.Text = "^l"
.Execute Replace:=wdReplaceAll
.Text = "^l^p"
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll
End With
End With
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


Kanga 85 said:
Thanks Graham,
I actually want lines rather than paragraphs, but I should be able to modify
your macro (or my docu,ment).
 

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