Hi, I need help running a macro on various word documents using a list of the file paths/names.
I have two .xls files - one with the macro (which I got off this forum, I think) and some text in two columns. The macro currently opens a specific word document, finds text from column A, and replaces it with text in column B. Instead of opening the specific word document and performing the find/replace, I want it to go through a list of about 400 documents and do the same thing. The paths/filenames of the documents are listed in a separate .xls file. Here is the macro:
Sub conversion()
Dim WordApp As Object
Dim DocWord As Word.Document
Set WordApp = CreateObject("Word.Application")
Set DocWord = WordApp.Documents.Open("C:\Files\Document.doc")
Set myRange = DocWord.Content
myRange.Find.Execute FindText:=Cells(2, 1), ReplaceWith:=Cells(2, 2).Text, _
Replace:=wdReplaceAll
myRange.Find.Execute FindText:=Cells(3, 1), ReplaceWith:=Cells(3, 2).Text, _
Replace:=wdReplaceAll
myRange.Find.Execute FindText:=Cells(4, 1), ReplaceWith:=Cells(4, 2).Text, _
Replace:=wdReplaceAll
DocWord.Close True
Set DocWord = Nothing
Set WordApp = Nothing
End Sub
If anyone could help I would be ever so grateful. Thank you!
I have two .xls files - one with the macro (which I got off this forum, I think) and some text in two columns. The macro currently opens a specific word document, finds text from column A, and replaces it with text in column B. Instead of opening the specific word document and performing the find/replace, I want it to go through a list of about 400 documents and do the same thing. The paths/filenames of the documents are listed in a separate .xls file. Here is the macro:
Sub conversion()
Dim WordApp As Object
Dim DocWord As Word.Document
Set WordApp = CreateObject("Word.Application")
Set DocWord = WordApp.Documents.Open("C:\Files\Document.doc")
Set myRange = DocWord.Content
myRange.Find.Execute FindText:=Cells(2, 1), ReplaceWith:=Cells(2, 2).Text, _
Replace:=wdReplaceAll
myRange.Find.Execute FindText:=Cells(3, 1), ReplaceWith:=Cells(3, 2).Text, _
Replace:=wdReplaceAll
myRange.Find.Execute FindText:=Cells(4, 1), ReplaceWith:=Cells(4, 2).Text, _
Replace:=wdReplaceAll
DocWord.Close True
Set DocWord = Nothing
Set WordApp = Nothing
End Sub
If anyone could help I would be ever so grateful. Thank you!