I'm a VBA beginner and o want to replace text and add new one line on the same open word document. But i have tried this piece of code but id doesn't work.
Sub open_word_replace_text()
Dim book1 As Word.Application
Dim sheet1 As Word.Document
Set book1 = CreateObject("word.application")
book1.Visible = True
Set sheet1 = book1.Documents.Open("Template.docx")
With sheet1.Content.Find
.Text = "prova"
.Replacement.ClearFormatting
.Replacement.Text = (Sheets("Sheet2").Range("A2").Value) & " " & (Sheets("Sheet2").Range("B2").Value)
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
.Forward = True
End With
'the following part must be write after the replace as new line on the word document and same paragraph
sheet1.Content.Text = (Sheets("Sheet2").Range("C2").Value)
end sub
Could you please someone help me? Thank you in advance.
I don't find a solutions
Microsoft documentation:
Update: