Find/Replace crashes Word

R

rogsonl

I created the following macro to change keys embedded in a document with text
depending on a database record. The macro was created by capturing it in
Word:
-----------------
Sub ReplaceInBody(xWhat As String, xTo As String, xMatchCase As Boolean)
'
' ReplaceInBody Macro
'
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = xWhat
.Replacement.Text = xTo
.Forward = True
.Wrap = wdFindContinue
.Format = False
If xMatchCase Then
.MatchCase = True
Else
.MatchCase = False
End If
.MatchWholeWord = False
.MatchKashida = False
.MatchDiacritics = False
.MatchAlefHamza = False
.MatchControl = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
---------------------------------
When I call the macro with parameters it freezes.
I believe that the "force Word to close" leaves garbage on the system after
Word closes, since even a straight forward find/replace after this on a new
version of Word causes it to crash.
I am moving back to 2003 since I need to be able to work.
Let me know if anyone has a fix for this problem. I'll leave 2007 installed
for a few days while waiting.
Leon
PS. I went through the diagnostics on 2007, the system came out clean.
 

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