I have a word doc with text and there is also a date text in there showing this format:
text text text 17.01.2020 text text text.
I want to replace the above date text with a cell from Excel that is also a date looking like this 18.01.2020.
So the VBA code should do the following:
1.Open word doc
2.find the text and replace it with the one from Excel
3.save Word doc.
Sub DocSearchandReplace()
Dim wdApp As Object, wdDoc As Object
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open("C:\sampletest.docx")
With wdDoc.Content.Find
.Date = "???"
.Replacement.Cell = "referencing a cell from Excel??"
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
wdDoc.Save 'it however always prompt a word warning, how to surpress it?
wdDoc.Close 'it only closes the doc inside Word without closing the whole program.
Set wdApp = Nothing: Set wdDoc = Nothing
End Sub
I am not sure what to write in the .Date and .Replacement.Cell sections.
.Date = "???"
does not exist in.Content.Find
– Pᴇʜ