Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

opcion 2

Sub generar_word()
Dim wdApp As Word.Application
Dim wdDocument As Word.Document
Dim documentPath As String, search As String, replacement As String

documentPath = ActivateSheet.Range("B46").Value
search = ActivateSheet.Range("E10").Value
replacement = ActivateSheet.Range("D10").Value

Set wdApp = New Word.Application


wdApp.Visible = True
Set wdDocument = wdApp.Documents.Open(Filename = documentPath, ReadOnly:=True)

Call findAndReplace(search, replacement, wdDocument)

Set dwApp = Nothing


Set dwDocument = Nothing

End Sub

Sub findAndReplace(strSearch As String, strReplacement As String, doc As


Word.Document)
With doc.Range.Find
.Text = strSearch
.Forward = True
.replacement.ClearFormatting
.replacement.Text = strReplacement
.Execute.Replace = wdReplaceAll.Forward = True

End With

End Sub

You might also like