white_flag
06-01-2011, 05:45 AM
Hello I have this code and it is not working:
Sub search_insert()
Dim objWdApp As Word.Application
Dim objWdDoc As Word.Document
Dim objWdRange As Word.Range
Dim bFound As Boolean, i As Long
Set objWdDoc = objWdApp.ActiveDocument
objWdApp.Visible = True
start counter at -1
i = -1
Do
Set objWdRange = objWdDoc.Content
With objWdRange.Find
.ClearFormatting
.Replacement.ClearFormatting
'Check if word is found
bFound = .Execute(findtext:="5656565", replaceWith:="found", Replace:=wdReplaceOne)
'increment counter
i = i + 1
End With
Loop While bFound
MsgBox CStr(i) & " replacements made."
Set objWdRange = Nothing
Set objWdDoc = Nothing
Set objWdApp = Nothing
End Sub
I have error '91' on this
Set objWdDoc = objWdApp.ActiveDocument
Sub search_insert()
Dim objWdApp As Word.Application
Dim objWdDoc As Word.Document
Dim objWdRange As Word.Range
Dim bFound As Boolean, i As Long
Set objWdDoc = objWdApp.ActiveDocument
objWdApp.Visible = True
start counter at -1
i = -1
Do
Set objWdRange = objWdDoc.Content
With objWdRange.Find
.ClearFormatting
.Replacement.ClearFormatting
'Check if word is found
bFound = .Execute(findtext:="5656565", replaceWith:="found", Replace:=wdReplaceOne)
'increment counter
i = i + 1
End With
Loop While bFound
MsgBox CStr(i) & " replacements made."
Set objWdRange = Nothing
Set objWdDoc = Nothing
Set objWdApp = Nothing
End Sub
I have error '91' on this
Set objWdDoc = objWdApp.ActiveDocument