Hi everyone, I'm hoping someone could help me with this issue I'm having:
I am in the middle of automating a process here at work, the program takes a word, "pencil" for example, from excel. It will then open up a word document with content already in it (premade template). The program will then find all instances of a string, "placepencilhere" for example, and will replace that instance with the string from excel.
Basically I want to be able to take a variable that has a stored string value from excel and use it to replace another variable in a word document.
I tried recording a replace (ctrl+f, replace tab) macro, copying the code, and inserting it into the excel vba code.. but I get a error message. Here is what I have:
---
Sub Replacing()
Dim xxx As String
xxx = "testing_template"
replacethis = "Pencil"
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Open("C:\Announcement_Templates\BE\" + xxx + ".doc")
Selection.Find.ClearFormatting (HERE IS WHERE I GET THE ERROR MESSAGE, THIS SECTION OF THE CODE WAS COPIED FROM WORD VBA)
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "placepencilhere"
.Replacement.Text = replacethis
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
---
Any help is appreciated! Thanks in advance!
odo-
Bookmarks