I have a folder with about 300 word docs that I need to do a find and replace of the same line of text. Normally, I would use scripting with the file system object. I found some code, but it is giving me an error 5111 http://support.microsoft.com/kb/920229
OS: Win 7 64 bit Pro
Word version 15.0
Visual basic 6.0
Any ideas how to make this run?
Public Function WordSwap()
Dim WordApp As New Word.Application
Dim Swap As Integer
Swap = 0
.LookIn = "D:\mark\Desktop\op notes done" ' where to search
.SearchSubFolders = True ' search the subfolders
.FileName = "*.doc" ' file pattern to match
' if more than one match, execute the following code
If .Execute() > 0 Then
' for each file you find, run this loop
For i = 1 To .FoundFiles.Count
' open the file based on its index position
' search and replace the address
.Text = "OldAddress"
.MatchCase = True
.Replacement.Text = "NewAddress"
Swap = Swap + 1
' replace e-mail address
.Text = "Oldemail"
.Replacement.Text = "Newemail"
' save and close the current document
' if the system cannot find any files
' with the .doc extension
MsgBox "No files found."
MsgBox "There were a total of " & i & " files to process. Changes were made in " & Swap & " files."