Object deleted error during replace

F

Frank

I have VBA macro that populates a string array (100,2) with incorrect and
correct strings. It steps through a FOR...NEXT loop, globally replacing each
incorrect string in the document with a correct string. On some documents
I'm getting an error that says "Object has been deleted," and when I hover
over .Text and .Replacement.Text, the tip says that the object has been
deleted. Sometimes it gets through the replacement loop, but then the error
will occur on replace operations that follow the loop. Sometimes, it works
just fine. Any thoughts?
 
F

Fumei2 via OfficeKB.com

Post the relevant code.
I have VBA macro that populates a string array (100,2) with incorrect and
correct strings. It steps through a FOR...NEXT loop, globally replacing each
incorrect string in the document with a correct string. On some documents
I'm getting an error that says "Object has been deleted," and when I hover
over .Text and .Replacement.Text, the tip says that the object has been
deleted. Sometimes it gets through the replacement loop, but then the error
will occur on replace operations that follow the loop. Sometimes, it works
just fine. Any thoughts?
 
F

Frank

Here's the code:

Dim CX(100, 2) As String, c As Single, Incorrect As Single, Correct As Single
Incorrect = 1
Correct = 2
CX(1, Incorrect) = "F. 2d"
CX(1, Correct) = "F.2d"
‘Etc.

c = 96

Selection.HomeKey unit:=wdStory, Extend:=wdMove
With Selection.Find
.ClearAllFuzzyOptions
.ClearFormatting
.Wrap = wdFindContinue
.Forward = True
.Replacement.ClearFormatting
For i = 1 To c
.Text = CX(i, Incorrect)
.Replacement.Text = CX(i, Correct)
.Execute Replace:=wdReplaceAll
Next i
Selection.HomeKey unit:=wdStory, Extend:=wdMove

Selection.Collapse direction:=wdCollapseEnd
.Text = ""
.Replacement.Text = ""
.ClearFormatting
.Replacement.ClearFormatting

End With

Selection.HomeKey unit:=wdStory, Extend:=wdMove
With Selection.Find
.ClearAllFuzzyOptions
.ClearFormatting
.Replacement.ClearFormatting
.Replacement.Text = ""
.Text = “Bankr.â€
.Forward = True
.Wrap = wdFindStop
.Execute Replace:=wdReplaceNone
While .Found
Selection.Collapse direction:=wdCollapseEnd
If Selection.Text <> " " Then Selection.InsertAfter Text:=" "
Selection.Collapse direction:=wdCollapseEnd
.Execute
Wend
End With
 
F

Frank

Any thoughts as to why the find object should suddenly be deleted? Could
there be a memory problem with running a replace repeatedly?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top