If not found ignore

S

Steved

Hello from Steved

Please how can I tell the below code that if "L [0-9 ]" is not found ignore
and goto "R [0-9 ]"

Thankyou.

Selection.Find.ClearFormatting
With Selection.Find
.Text = "L [0-9 ]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=2
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=", "
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.Find.ClearFormatting
With Selection.Find
.Text = "R [0-9 ]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=2
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=", "
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine
 
T

Tony Jollans

If Selection.Find.Execute = true Then
' Found so do whatever
Else
' Not found so don't do it
End If
' Get on with your life

The code you have looks like it has been recorded and it would probably be
as well to rework it so it wasn't emulating cursor movementand working with
Lines which are fickle things in Word - your Delete, for example, may or may
not make enough room on the line for the first word on the next line to flow
up.
 
S

Steved

Thankyou

Tony Jollans said:
If Selection.Find.Execute = true Then
' Found so do whatever
Else
' Not found so don't do it
End If
' Get on with your life

The code you have looks like it has been recorded and it would probably be
as well to rework it so it wasn't emulating cursor movementand working with
Lines which are fickle things in Word - your Delete, for example, may or may
not make enough room on the line for the first word on the next line to flow
up.

--
Enjoy,
Tony

Steved said:
Hello from Steved

Please how can I tell the below code that if "L [0-9 ]" is not found
ignore
and goto "R [0-9 ]"

Thankyou.

Selection.Find.ClearFormatting
With Selection.Find
.Text = "L [0-9 ]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=2
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=", "
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.Find.ClearFormatting
With Selection.Find
.Text = "R [0-9 ]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=2
Selection.EndKey Unit:=wdLine
Selection.TypeText Text:=", "
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine
 

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