View Full Version : [SOLVED:] Run-time error “5525” on the code: Dialogs(wdEditReplace).Show
Ice-Tea-Jan
07-02-2009, 01:58 PM
Hello,
The macro I wrote populates the EditReplace dialog box; and then “Shows” it so the operator can simply proceed with the search.
However, if the operator chooses to “Replace All” and then uses “Close” or “X’s out” of this box, a Run-Time error '5525' appears: "Word has completed its search of the header/footer and has made 1 replacement."
The debug code stops here:
Dialogs(wdDialogEditReplace).Show
It doesn’t seem to make a difference whether I use “Show” or “Display” at the end of this line--?:dunno
Can somebody suggest a fix?
Thanking you,
Janet
fumei
07-02-2009, 03:22 PM
"The debug code stops here:
Dialogs(wdDialogEditReplace).Show"
That's nice, but without the rest of the code it is hard to make any real suggestions.
More details may help.
Is this only for headers/footers? Are there more than one header/footer to be actioned?
""Word has completed its search of the header/footer and has made 1 replacement."
Who knows...maybe there IS only one header/footer.
BTW: you can error-trap the Close event of the dialog.
Ice-Tea-Jan
07-02-2009, 04:20 PM
The search is to look everywhere -- not just headers/footers -- it just so happened that in that search session, the material replaced was in the headers/footers:
My code -- but the debug stops at the last line of code
Sub RunTimeErrorTest()
If MsgBox ("This populates the Find and Replace box to search ~WAVY~ underlines and replace it with ~GRAY SHADING~." & vbCrLf & vbCrLf _
& "You will control the actual search session.", vbOKCancel + vbExclamation, "Search strings will load. . . ") = vbCancel Then Exit Sub
' Populates search box with wavy underline with shading
' Checks if either Edit Find or Edit Replace Dialog Box is open, if so it closes it
If Dialogs(wdDialogEditFind) = Show Then
Dialogs(wdDialogEditFind).Close
End If
If Dialogs(wdDialogEditReplace) = Show Then
Dialogs(wdDialogEditReplace).Close
End If
' Sets the highlighter to default to Gray for the search/replace highlight
Options.DefaultHighlightColorIndex = wdGray25
' Important: Clears formatting specs on both find and replace area for both text and formatting!
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
' Loads up the Find (font) to search underline wavy
With Selection.Find
.Text = ""
.Font.Underline = wdUnderlineWavy
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
' Loads up the Replace (font) to replace with underline single
With Selection.Find.Replacement
.Text = ""
.Font.Underline = noUnderline
.Highlight = True
End With
Dialogs(wdDialogEditReplace).Show
End Sub
Ice-Tea-Jan
07-02-2009, 04:21 PM
It sounds like I do need an error-trap?
Ice-Tea-Jan
07-05-2009, 08:36 AM
Hello Folks,
I will mark this solved as soon as I retest it on a higher version of VB.
I believe I squashed the VB run-time error by inserting a (?generic?) error handler. I feel soo newbie! :doh:
Actually, I HAD attempted the error handler earlier, but since the VB code itself gave no errors, I presumed it simply did not work on the particular circumstance at hand. I'm sure something was wrong with my previous attempts at the error handler -- perhaps its placement?
Thanks for the tip that sent me back to refocus upon trying the error handler once again.
I appears to work in the older VB version I have here now, however I will retest on a higher version tomorrow.
Thanks again,:thumb
Janet
Here is the new code (in red) using the error handler:
Sub TakeTwoRunTimeErrorTest()
If MsgBox ("This populates the Find and Replace box to search ~WAVY~ underlines and replace it with ~GRAY SHADING~." & vbCrLf & vbCrLf & _
"You will control the actual search session.", vbOKCancel + vbExclamation, "Search strings will load. . . ") = vbCancel Then Exit Sub
' Added this code since last post
On Error GoTo ErrorHandler
' Populates search box with wavy underline with shading
' Checks if either Edit Find or Edit Replace Dialog Box is already open -- if so, closes it
If Dialogs(wdDialogEditFind) = Show Then
Dialogs(wdDialogEditFind).Close
End If
If Dialogs(wdDialogEditReplace) = Show Then
Dialogs(wdDialogEditReplace).Close
End If
' Sets the highlighter to default to Gray for the search/replace highlight
Options.DefaultHighlightColorIndex = wdGray25
' Important: Clears formatting specs on both find and replace area for both text and formatting!
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
' Loads up the Find (font) to search underline wavy
With Selection.Find
.Text = ""
.Font.Underline = wdUnderlineWavy
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
' Loads up the Replace (font) to replace with underline single
With Selection.Find.Replacement
.Text = ""
.Font.Underline = noUnderline
.Highlight = True
End With
Dialogs(wdDialogEditReplace).Show
' Added this code since last post
ErrorHandler:
Exit Sub
End Sub
Ice-Tea-Jan
07-06-2009, 09:54 AM
Thanks Fumei!
Thanks for the tip that sent me back to refocus upon trying the error handler once again.
I does appear to work in the higher VB version.
Not sure about placement of this error handler; but it works to squash the benign error that was popping up.:*)
Janet
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.