-
Solved: Run-time error “5525” on the code: Dialogs(wdEditReplace).Show
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--?
Can somebody suggest a fix?
Thanking you,
Janet
-
"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.
-
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
-
It sounds like I do need an error-trap?
-
-
Solved! Thanks Fumei!
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules