I am looking for a simple VBA that will reference specific cells in Excel and use this date to do a find and replace in Word.
Example:
Cell B2 in Excel = John Smith
I want the VBA to take John Smith, search a specified Word document using that information, and replace all instances of John Smith with whatever value I choose, such as Sally Smith.
I would like to be able to repeat this process for as many cells as I please.
I found the code below, but it's potential seems limited to me. You have to manually enter the find and replace text in the VBA. I am looking for a way to make this automated.
I have done some searching and found all the different elements I am looking for. I can't seem to find anything that includes all my requests in one VBA.
Any help would be greatly appreciated!
Thanks!
Sub DocSearch()
Dim wdApp As Object, wdDoc As Object
Set wdApp = CreateObject("word.application")
wdApp.Visible = True
Set wdDoc = wdApp.Documents.Open("C:\Documents and Settings\Owner\My Documents\downloads\work\M-F-380.1.doc")
With wdDoc.Content.Find
.Text = "Date:"
.Replacement.Text = "Datetest"
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll
End With
Set wdApp = Nothing: Set wdDoc = Nothing
End Sub
Bookmarks