View Single Post
 
Old 12-28-2021, 09:51 PM
Bikram Bikram is offline Windows 10 Office 2007
Advanced Beginner
 
Join Date: Jul 2021
Location: Nepal
Posts: 90
Bikram is on a distinguished road
Default Conditional_Replacing

Hello, I am using find and replace and it seems to work fine but I need to modify it. Here is the code.

Code:
Sub findMm()
Dim strfind() As Variant
Dim strreplace() As Variant
Dim i As Integer
    strfind = Array("A", "An", "The", "To", "With" )
    strreplace = Array("a", "an", "the", "to","with")
    For i = 0 To UBound(strfind)
        With Selection.find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = strfind(i)
            .Format = True
            .Forward = True
            .MatchWildcards = False
            .MatchCase = True
            .Replacement.Text = strreplace(i)
            .Execute Replace:=wdReplaceAll
        End With
    Next i
End Sub
What I want to do here is to replace the found items only if they are in the middle of the sentences and ignore them if they are at the beginning of the sentences.

For Example:
To Find The Answer Of The Question.
With The Help Of People.

Replace the text except for the first word

To Find the Answer to the Question.
With the help of People.

How can it be done?? Thanks in advance.
Reply With Quote