Need to loop this code

2

2Catman

I need to loop the following code: It is used in a text file that is a
comma-delimited database of journal references. Each reference has 45 fields,
each field is enclosed in quotes and separated by commas. I need to count 11
fields in, add a comma, go the end of the record (a paragraph mark) and then
repeat for the remaining records until the end of the document.

Here is the code I have so far:

Sub Test_find_count()
'
' Test_find_count Macro
' Macro recorded 12/5/2005 by
'
Selection.Find.ClearFormatting

With Selection.Find
.Text = ""","
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

For X = 1 To 11
Selection.Find.Execute
Next X

Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeText Text:=", "

With Selection.Find
.Text = "^p"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute


End Sub
 
D

Doug Robbins - Word MVP

I believe that you can probably do what you want (though I can't work out
from your description, or code, exactly what it is) with a wildcard Find and
Replace.

See the article "Finding and replacing characters using wildcards" at:

http://www.word.mvps.org/FAQs/General/UsingWildcards.htm


--
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
 

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