D
Designingsally
Hi
take a look at the code given below. Now try runnin the macro with sentence.
" Hi. I m fine. Where were you. I went to my native. I bought many dressees.
my parents are fine too. I also bought many others.
In this the macros replaces all FINE first and then MANY. But I want the
macro to change the words as can when they occur.
Can someone help me out?
Sub check()
Dim orng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
sFindText = "fine" 'the word to find
sRepText = "finD" 'the word to replace
With Selection
..HomeKey wdStory
With .Find
..ClearFormatting
..Replacement.ClearFormatting
..Wrap = wdFindContinue
..Format = False
..MatchCase = True
..MatchWholeWord = True
..MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace with finD?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend
sFindText = "many" 'the word to find
sRepText = "ues" '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 with uses?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend
End With
End With
End With
End With
End Sub
take a look at the code given below. Now try runnin the macro with sentence.
" Hi. I m fine. Where were you. I went to my native. I bought many dressees.
my parents are fine too. I also bought many others.
In this the macros replaces all FINE first and then MANY. But I want the
macro to change the words as can when they occur.
Can someone help me out?
Sub check()
Dim orng As Range
Dim sRep As String
Dim sFindText As String
Dim sRepText As String
sFindText = "fine" 'the word to find
sRepText = "finD" 'the word to replace
With Selection
..HomeKey wdStory
With .Find
..ClearFormatting
..Replacement.ClearFormatting
..Wrap = wdFindContinue
..Format = False
..MatchCase = True
..MatchWholeWord = True
..MatchAllWordForms = False
While .Execute(findText:=sFindText)
Set orng = Selection.Range
sRep = Msgbox("Replace with finD?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend
sFindText = "many" 'the word to find
sRepText = "ues" '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 with uses?", vbYesNoCancel)
If sRep = vbCancel Then
Exit Sub
End If
If sRep = vbYes Then
orng.Text = sRepText
End If
Wend
End With
End With
End With
End With
End Sub