Hi
An exapple of what I am trying to do is:
find the string "ABC" in word docs and replace it with the string "123"
Wverything works except for the replace bit
any ideas? thanks
Dim fnd As String
Dim wrd As Object
Dim str As String
With Application.FileSearch
.NewSearch
.LookIn = "C:\"
.SearchSubFolders = True
.FileName = "*.doc"
.TextOrProperty = "ABC"
.MatchTextExactly = True
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
fnd = fnd & Chr(13) & Chr(10) & .FoundFiles(i)
Set wrd = CreateObject("Word.Application")
wrd.Visible = True
wrd.Documents.Open .FoundFiles(i)
With wrd.Selection.Find
.Text = "ABC"
.Replacement.Text = "123"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wrd.Selection.Find.Execute Replace:=wdReplaceAll
Next i
Set wrd = Nothing
Else
MsgBox "There were no files found."
End If
End With
Txtfound.Value = fnd
An exapple of what I am trying to do is:
find the string "ABC" in word docs and replace it with the string "123"
Wverything works except for the replace bit
any ideas? thanks
Dim fnd As String
Dim wrd As Object
Dim str As String
With Application.FileSearch
.NewSearch
.LookIn = "C:\"
.SearchSubFolders = True
.FileName = "*.doc"
.TextOrProperty = "ABC"
.MatchTextExactly = True
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
fnd = fnd & Chr(13) & Chr(10) & .FoundFiles(i)
Set wrd = CreateObject("Word.Application")
wrd.Visible = True
wrd.Documents.Open .FoundFiles(i)
With wrd.Selection.Find
.Text = "ABC"
.Replacement.Text = "123"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wrd.Selection.Find.Execute Replace:=wdReplaceAll
Next i
Set wrd = Nothing
Else
MsgBox "There were no files found."
End If
End With
Txtfound.Value = fnd