Option Explicit
Private Sub Command1_Click() Dim oWord As Word.Application Dim oDoc As Word.Document ' This procedure demonstrates using the Execute ' method to replace text. Set oWord = GetObject(, "Word.Application") If oWord Is Nothing Then Set oWord = CreateObject("Word.Application") End If oWord.Documents.Open FileName:="c:\test.doc" oWord.Documents("test.doc").Activate Set oDoc = oWord.ActiveDocument ' Loop until no more items are found. Do oWord.Selection.Find.ClearFormatting With oWord.Selection.Find .Text = "display" .Execute ReplaceWith:="show", _ Replace:=wdReplaceAll, Forward:=True End With ' Exit the loop when the search is unsuccessful. If oWord.Selection.Find.Execute = False Then Exit Do Loop End Sub |