Consulting

Results 1 to 6 of 6

Thread: Solved: Run-time error “5525” on the code: Dialogs(wdEditReplace).Show

  1. #1

    Post 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

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    "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.

  3. #3
    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

  4. #4
    It sounds like I do need an error-trap?

  5. #5

    Smile

    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!
    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,
    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

  6. #6

    Wink 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
  •