Hello All,
Can anyone show me some sample code on how to insert/replace a word in a Microsoft Word Document. The code below will find the word, but how do I insert the replacement word? Please HELP! Thanks in advance.
Public Sub OpenWord()
Dim obWordApp As Word.Application
Dim obWordDoc As Word.Document
Dim myRange As Word.Range
'Dim wdActiveDoc As Word.Document
Dim gOptions
Dim gCount As Integer
Dim TextToFind As String
Dim TextToChange As String
Dim Result As Integer
Set obWordApp = CreateObject("Word.Application")
Set obWordDoc = obWordApp.Documents.Open("C:\Temp\BLANK.doc")
'Set myRange = obWordDoc.Content
TextToFind = "F3"
TextToChange = "I Work"
myRange.Find.Execute FindText:=TextToFind, Forward:=True
'gOptions = rtfWholeWord
'Result = obWordDoc.Content.Find(TextToFind, 0, , gOptions)
If myRange.Find.Found <> True Then
MsgBox "Text not found"
Else
MsgBox "Text Found"
'How do I insert TextToChange
End If
obWordDoc.Quit
Set obWordDoc = Nothing
End Sub




Reply With Quote