S
Simon I
I have created a macro to replace one phrase with another.
Generally it runs correctly, but when I run it with the
last occurrence of the phrase in the document the macro
hangs. I have to press Esc to get back to the document.
If I then insert the phrase a few more times then run the
macro again it does nothing (as if it has been disabled).
Closing and opening the document again - and the macro
runs OK (until I get to the last occurrence again).
I note that if you do the same Replace from the menus,
Word tells you it has reached the end of the document and
awaits an OK. Is this my problem? - if so how do I deal
with it in the macro.?
Thanks for you help on this.
Here is the macro text:
+++++++++++++++++++++++++++++++++++
Sub noSig()
'
' noSig Macro
' Macro recorded 8/5/2004 by Simon
'
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*quote "
.Replacement.Text = "=removed by SI ="
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub
Generally it runs correctly, but when I run it with the
last occurrence of the phrase in the document the macro
hangs. I have to press Esc to get back to the document.
If I then insert the phrase a few more times then run the
macro again it does nothing (as if it has been disabled).
Closing and opening the document again - and the macro
runs OK (until I get to the last occurrence again).
I note that if you do the same Replace from the menus,
Word tells you it has reached the end of the document and
awaits an OK. Is this my problem? - if so how do I deal
with it in the macro.?
Thanks for you help on this.
Here is the macro text:
+++++++++++++++++++++++++++++++++++
Sub noSig()
'
' noSig Macro
' Macro recorded 8/5/2004 by Simon
'
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*quote "
.Replacement.Text = "=removed by SI ="
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1
End Sub