Link to home
Start Free TrialLog in
Avatar of rdy123 rdy
rdy123 rdy

asked on

text replacement instead of two macros only one macro

hi,

i created a macro for replacing text in word from excel,below is the code,but now i thinking the text to replace is same in one document but writing two macros for it,instead of two macros can we write only one macro so that both "abc" and "sendto" are replaced ,is this possible,any suggestions please.


Sub sent(fileLocation As String)


Dim oCell  As Integer
Dim WA As Object



On Error Resume Next
Set WA = GetObject(, "Word.Application")
On Error GoTo 0

If WA Is Nothing Then
    Set WA = CreateObject("Word.Application")
    WA.Documents.Open (fileLocation)
    WA.Visible = True
End If

WA.Selection.Find.ClearFormatting
WA.Selection.Find.Replacement.ClearFormatting
With WA.Selection.Find
        .Text = "abc"
        .Replacement.Text = Cells(Application.ActiveCell.Row, 17).Value
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
   
     End With
WA.Selection.Find.Execute replace:=wdReplaceAll
End Sub


Sub Mail(fileLocation As String)


Dim oCell  As Integer
Dim WA As Object



On Error Resume Next
Set WA = GetObject(, "Word.Application")
On Error GoTo 0

If WA Is Nothing Then
    Set WA = CreateObject("Word.Application")
    WA.Documents.Open (fileLocation)
    WA.Visible = True
End If

WA.Selection.Find.ClearFormatting
WA.Selection.Find.Replacement.ClearFormatting
With WA.Selection.Find
        .Text = "sendto"
        .Replacement.Text = Cells(Application.ActiveCell.Row, 6).Value & " " & Cells(Application.ActiveCell.Row, 7).Value
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
   
     End With
WA.Selection.Find.Execute replace:=wdReplaceAll
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rdy123 rdy
rdy123 rdy

ASKER

perfect,its working...thank you so much... :)