hi,
i wrote a code in excel, where i want to replace few text with the excel.
now the issue is, i work on same file and want to replace the text once the word document is open instead of opening again and replace it.
please suggest.
below is the code.
once the pathh = "C:\Templates\xxx.docx" is open,i want to keep this open and run the sent macro and replace the text,please suggest
i wrote a code in excel, where i want to replace few text with the excel.
now the issue is, i work on same file and want to replace the text once the word document is open instead of opening again and replace it.
please suggest.
below is the code.
Code:
Sub from()
Dim pathh As String
Dim pathhi As String
Dim oCell As Integer
Dim WA As Object
pathh = "C:\Templates\xxx.docx"
Set WA = CreateObject("Word.Application")
WA.Documents.Open (pathh)
WA.Visible = True
WA.Selection.Find.ClearFormatting
WA.Selection.Find.Replacement.ClearFormatting
With WA.Selection.Find
.Text = "abc"
.Replacement.Text = Cells(Application.ActiveCell.Row, 15).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 sent()
Dim pathh As String
Dim pathhi As String
Dim oCell As Integer
Dim WA As Object
pathh = "C:\Templates\xxx.docx"
Set WA = CreateObject("Word.Application")
WA.Documents.Open (pathh)
WA.Visible = True
WA.Selection.Find.ClearFormatting
WA.Selection.Find.Replacement.ClearFormatting
With WA.Selection.Find
.Text = "dddd, mmmm dd, yyyy t:tt"
.Replacement.Text = Cells(Application.ActiveCell.Row, 17).Value & " " & Cells(Application.ActiveCell.Row, 18).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
once the pathh = "C:\Templates\xxx.docx" is open,i want to keep this open and run the sent macro and replace the text,please suggest
Last edited by a moderator: