Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace Text in multiple Word Documents

Status
Not open for further replies.

HendrixD

Technical User
Dec 2, 2008
5
US
This is a repost from the Office forum with additional details.

Here is what I have to do. I am using MS Word 2003 and need to replace two separate paragraphs within the document, it is a job profile. There are 2200 of these documents in the same folder. There are other documents (another 2000 or so) within the same folder that are similar and have the same paragraphs but do not need to have the paragraphs replaced. They are differentiated by a union code within the document. There are 7 union codes to base the search off of.

Thanks for the help.
 
This is VBScript

Did you really want Forum707?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Script is possible. Here is a sample.

Code:
Dim fs, fil, fldr, strPath
Dim wd 

Set fs = CreateObject("Scripting.FileSystemObject")
strPath = InputBox("Enter Path of folder", "Find File")

If strPath = "" Or fs.FolderExists(strPath) = False Then
    MsgBox "Not a valid folder Path.", 64
    'WScript.Quit
End If

Set wd = CreateObject("Word.Application")
wd.Visible = True

Set fldr = fs.GetFolder(strPath)
For Each fil In fldr.Files
    If fil.Type = "Microsoft Word Document" Then
        
        wd.Documents.Open fil.Path
        
        wd.Selection.Find.ClearFormatting
        With wd.Selection.Find
            .Text = "LessThanDot"
            .Forward = True
        End With
        wd.Selection.Find.Execute
        If wd.Selection.Find.Found Then
            wd.Selection.Range = "Whatever"
        End If
        
        wd.Documents.Close
    End If
Next
wd.Quit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top