Replacing text in text box inside table
As we've moved company locations, I want to replace the street address on a large number of documents, all in the same folder. I've written code to replace the appropriate text throughout all the docs in the specified folder. It works just fine (main text, headers, footers, etc.), except for a text box that's inside a table cell. (I set up the cover of each doc as a 1 row x 3 column table. In cell(1,1), I have a text box that has the company's address.) Code follows - can anyone see what's wrong? This is driving me crazy(er).
Many thanks!
Larry
Sub FindReplaceAllDocsInFolder()
Dim I As Integer
Dim doc As Document
Dim rng As Range
Dim strFilePath As String
Dim intFilesFoundCount As Integer
With Application.FileSearch
.LookIn = "c:\Test"
.SearchSubFolders = False
.FileType = msoFileTypeWordDocuments
If Not .Execute() = 0 Then
For I = 1 To .FoundFiles.Count
Set doc = Documents.Open(.FoundFiles(I))
Set rng = doc.Range
For Each rng In doc.StoryRanges
With rng.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "111 West 5th"
.Replacement.Text = "2448 East 81st"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
Next rng
doc.Save
doc.Close
Set rng = Nothing
Set doc = Nothing
Next I
Else
x = MsgBox("No files matched " & .FileName, vbOKOnly, "No Files Matched")
End If
End With
End Sub
Larry Landis
Technical Writer
|