I've got a problem with my macro

S

Steved

Hello from Steved

Sub Outof()
ActiveDocument.Range.Find.Execute _
FindText:="(* Out of *) Out of *,", _
ReplaceWith:="\1,", _
MatchWildcards:=True, _
Replace:=wdReplaceAll
End Sub

The above to work on below please

by King Delamere out of Sister Noelene,
by Marauding out of Live It Up (AUS,
by Pharostan out of Gay Heights,
by Islero out of Azflora,

To be as below

by King Delamere,
by Marauding,
by Pharostan,
by Islero,

Thankyou.
 
D

Doug Robbins - Word MVP on news.microsoft.com

Use

Dim drange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="out of", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindContinue, MatchCase:=True) = True
Set drange = Selection.Bookmarks("\line").Range
drange.Start = Selection.Range.Start - 1
drange.Text = "," & vbCr
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, originally posted via msnews.microsoft.com
 
S

Steved

Hello Doug from Steved

Firstly thankyou, you macro does 90% as intended.
Can you see why it is doing to the below

by Grosvenor out of Hinewai, $1,000, L 4:0:1, R 0:0:0

is leaving
by Grosvenor

Should be please
by Grosvenor, $1,000, L 4:0:1, R 0:0:0

by Kaapstad out of Star On Ice, $3,900, L 3:1:0, R 0:0:0

is leaving
by Kaapstad

Should be please
by Kaapstad, $3,900, L 3:1:0, R 0:0:0

Thankyou.
 
D

Doug Robbins - Word MVP on news.microsoft.com

It is not doing what you now say you want, because that is not what you
previously said that you want.

If you had said that was what you wanted, I would have told you to use this:

Dim drange As Range
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="out of", Forward:=True, _
MatchWildcards:=False, Wrap:=wdFindContinue, MatchCase:=True) = True
Set drange = Selection.Bookmarks("\line").Range
drange.Start = Selection.Range.Start - 1
drange.End = drange.Start + InStr(drange, ",") - 1
drange.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, originally posted via msnews.microsoft.com
 
S

Steved

Hello doug from Steved

Firstly I'm very sorry for the confusion my fault.

I Thankyou.

Excellent job as always

Steved
 

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