D
Designingsally
I got this sample data.
I love you. I love this world. I love this country. I love myself.
I got this find and replace macro which ll replace love to hate. when i m in
the third love in the given sentence i realise that i want to undo the
previous process (second love in the sentence)
The macro code I got uses the YES, NO, CANCEL buttons.
On hitting the CANCEL button, macro searches the word of previous instance.
If any, it changes the previous instance.
Now I want the macros to do is NOT to replace the word of previous instance
but JUST highlight the word alone and show the message box as "The
Recommended Word is and so on. Replace? with YES, NO, CANCEL button", so
that user has the discretion to replace the word or skip the word. And l also
want the macros continue the process of find and replace even after the
previous instance is found or not.
My macro code partially satisfies the process but i m unable to ask macro to
just highlight the word and then continuing to have the message as mentioned
in the above para.
Can someone help me out with this? Is it possible to modify?
Thanks in advance
Dim orng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
Dim boolChanged As Boolean
sFindText = "love" 'the word to find
sRepText = "hate" 'the word to replace
boolChanged = False
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = MsgBox("The Recommended Word is and so on. Replace?",
vbYesNoCancel)
If sRep = vbCancel Then
If boolChanged Then
ActiveDocument.Undo
Exit Sub
Else
MsgBox "You cannot undo the last change as there was no
last change."
Exit Sub
End If
End If
If sRep = vbYes Then
orng.Text = sRepText
boolChanged = True
End If
Wend
End With
End With
I love you. I love this world. I love this country. I love myself.
I got this find and replace macro which ll replace love to hate. when i m in
the third love in the given sentence i realise that i want to undo the
previous process (second love in the sentence)
The macro code I got uses the YES, NO, CANCEL buttons.
On hitting the CANCEL button, macro searches the word of previous instance.
If any, it changes the previous instance.
Now I want the macros to do is NOT to replace the word of previous instance
but JUST highlight the word alone and show the message box as "The
Recommended Word is and so on. Replace? with YES, NO, CANCEL button", so
that user has the discretion to replace the word or skip the word. And l also
want the macros continue the process of find and replace even after the
previous instance is found or not.
My macro code partially satisfies the process but i m unable to ask macro to
just highlight the word and then continuing to have the message as mentioned
in the above para.
Can someone help me out with this? Is it possible to modify?
Thanks in advance
Dim orng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
Dim boolChanged As Boolean
sFindText = "love" 'the word to find
sRepText = "hate" 'the word to replace
boolChanged = False
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = MsgBox("The Recommended Word is and so on. Replace?",
vbYesNoCancel)
If sRep = vbCancel Then
If boolChanged Then
ActiveDocument.Undo
Exit Sub
Else
MsgBox "You cannot undo the last change as there was no
last change."
Exit Sub
End If
End If
If sRep = vbYes Then
orng.Text = sRepText
boolChanged = True
End If
Wend
End With
End With