error closing dialog

Ö

Örjan Skoglösa

I´m showing the built-in Find&Replace dialog and manually executing a
replacement.

Upon closing the dialog I get a "running error" 5452 or 5524 with the
text that normally is shown after execution ("Word has made #
replacements".)

How can I avoid this error?

The code I use:

Selection.Find.Replacement.Font.Bold = False
With Dialogs(wdDialogEditReplace)
.Find = "SW-T:"
.Replace = "^&"
.Direction = True
.FindNext = wdFindAsk
.Format = True
.MatchCase = False
.WholeWord = False
.PatternMatch = False
.SoundsLike = False
.FindAllWordForms = False
.Show
End With


TIA
Örjan Skoglösa
 
K

Klaus Linke

Hi Örjan,

Word (mis-)uses an error message to show the number of replacements.

If you search from the user interface, Word obviously suppresses part of the
error message. You could try to catch the error with "On Error", and display
the part with the number of replacements yourself.

On Error GoTo ErrHandler
Selection.Find.Replacement.Font.Bold = False
With Dialogs(wdDialogEditReplace)
' ...
End With
Exit Sub
ErrHandler:
Select Case Err.Number
Case 5452
MsgBox Err.Description, vbInformation
Case 5524
MsgBox Err.Description, vbInformation
Case Else
Err.Raise Number:=Err.Number
End Select

Regards,
Klaus
 

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