Adding a "prefix" to every line in a list.

W

Walter

I need to add "front:" and "back" anlternatively to every line in a long list.
I don't think search-ad-replace will do.
A macro of sort?
Thanks for helping.
 
S

Shasur

Hi

Here is a sample you can work on

Sub Tag_Lists()

Dim oLF As ListFormat
Dim oLst As List
Dim oPara As Paragraph

For Each oLst In ActiveDocument.Lists


For Each oPara In oLst.ListParagraphs
oPara.Range.Select
Selection.InsertBefore "front:"
Selection.Collapse wdCollapseEnd
Selection.MoveLeft
Selection.TypeText "back"
Next oPara

Next oLst

End Sub



Cheers
Shasur
 
D

Doug Robbins - Word MVP

Something like:

Dim i As Long
With Selection
For i = 1 To .Paragraphs.Count Step 2
.Paragraphs(i).Range.InsertBefore "Front "
If i + 1 <= .Paragraphs.Count Then
.Paragraphs(i + 1).Range.InsertBefore "Back "
End If
Next
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
K

Klaus Linke

Walter said:
I need to add "front:" and "back" anlternatively to every line in a long
list.
I don't think search-ad-replace will do.


Hi Walter,

It will. Just select the list along with the preceeding paragraph mark, but
without the last paragraph mark.
Then replace ^p with ^& plus whatever you want to add at the beginning.

Find/Replace even works fine if you don't have a contiguous list in which
you want to replace, but if you want to insert something at the start (or
end) depending on some criterion.

I often insert tags around paragraphs that are formatted in some paragraph
style, say "Heading 1".

Check "Match wildcards",

Find what: ([!^13]@)(^13)
and while in "Find what", go in "Format > Style" and select "Heading 1"
Replace with: <H1>\1</H1>\2

Regards,
Klaus
 

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