How do I use Do...Loop

2

2Catman

I have a comma-delimited word file that needs a lot of formatting. In one
case I have to find the comma delimiter multiple times until I get to the
correct place and then make a change. This is repeated until all the changes
are made for that record. Each record is ended with a paragraph mark. I have
created a macro that will change the first record correctly, and if I keep
running the macro it keeps correcting on down through the document. However,
I haven't been able to create a Do...Loop statement that works correctly to
do it automatically.

Here is the macro I have so far...

Sub Test_find_count()
'
' Test_find_count Macro
' Macro recorded 12/5/2005 by John Walsh
'
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 12
Selection.Find.Execute
Next X

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

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

Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="Volume "

Selection.Find.Execute

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

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

Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="Issue "

Selection.Find.Execute

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

Selection.Find.Execute

Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.TypeText Text:="pp. "


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
 
D

Doug Robbins - Word MVP

I haven't tried to work out what your code is doing, but here is how you use
a Do... Loop

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="MacWordNew", MatchWildcards:=False,
Wrap:=wdFindContinue, Forward:=True) = True
Selection.Paragraphs(1).Range.Delete
Loop
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
 

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