D
Designingsally
Hi there
I got find and replace as shown below.
The word I desire to find is dialog and replace the word with dialog box. As
I run the macro, it correctly finds the word dialog, and replaces with dialog
box. When I run it again, it again finds dialog in word "dialog box" and
replaces it with dialog . Is it possible for macro not to carry out this
process. As the word as been replaced and it is not intelligent if the macro
could change the replaced word again and again.
I ll be glad if someone could come with some code which can overcome this
code.
Thanks for helping a novice.
Sally
Sub FindAndReplace()
' FindAndReplace Macro
Dim orng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
sFindText = "dialog" 'the word to find
sRepText = "dialog box" 'the word to replace
With Selection
..HomeKey wdStory
With .Find
..ClearFormatting
..Replacement.ClearFormatting
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend
End Sub
I got find and replace as shown below.
The word I desire to find is dialog and replace the word with dialog box. As
I run the macro, it correctly finds the word dialog, and replaces with dialog
box. When I run it again, it again finds dialog in word "dialog box" and
replaces it with dialog . Is it possible for macro not to carry out this
process. As the word as been replaced and it is not intelligent if the macro
could change the replaced word again and again.
I ll be glad if someone could come with some code which can overcome this
code.
Thanks for helping a novice.
Sally
Sub FindAndReplace()
' FindAndReplace Macro
Dim orng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
sFindText = "dialog" 'the word to find
sRepText = "dialog box" 'the word to replace
With Selection
..HomeKey wdStory
With .Find
..ClearFormatting
..Replacement.ClearFormatting
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend
End Sub