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.Applica tion")
WA.Documents.Open (fileLocation)
WA.Visible = True
End If
WA.Selection.Find.ClearFor matting
WA.Selection.Find.Replacem ent.ClearF ormatting
With WA.Selection.Find
.Text = "abc"
.Replacement.Text = Cells(Application.ActiveCe ll.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.Applica tion")
WA.Documents.Open (fileLocation)
WA.Visible = True
End If
WA.Selection.Find.ClearFor matting
WA.Selection.Find.Replacem ent.ClearF ormatting
With WA.Selection.Find
.Text = "sendto"
.Replacement.Text = Cells(Application.ActiveCe ll.Row, 6).Value & " " & Cells(Application.ActiveCe ll.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
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.Applica
WA.Documents.Open (fileLocation)
WA.Visible = True
End If
WA.Selection.Find.ClearFor
WA.Selection.Find.Replacem
With WA.Selection.Find
.Text = "abc"
.Replacement.Text = Cells(Application.ActiveCe
.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.Applica
WA.Documents.Open (fileLocation)
WA.Visible = True
End If
WA.Selection.Find.ClearFor
WA.Selection.Find.Replacem
With WA.Selection.Find
.Text = "sendto"
.Replacement.Text = Cells(Application.ActiveCe
.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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER