Share via

Search & replace macro returns error

Anonymous
2012-11-13T10:30:02+00:00

I'm trying to run what I thought was a simple search & replace macro in Word 2011, to replace manual line breaks with paragraph marks. The macro is:

Sub ReplaceManualLineBreaks()

'

' ReplaceManualLineBreaks Macro

'

'

Selection.Find.ClearFormatting

Selection.Find.Replacement.ClearFormatting

With Selection.Find

.Text = "^|"

.Replacement.Text = "^p"

.Forward = True

.Wrap = wdFindContinue

.Format = False

.MatchCase = False

.MatchWholeWord = True

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute Replace:=wdReplaceAll

End Sub

However, on running it, I get the error message:

Run-time error '5625':

{a} is not a valid special character for the Find What box.

When I opt or debug, that line near then end - Selection.Find.Execute Replace:=wdReplaceAll - is highlighted. Any thoughts?

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-11-13T10:46:16+00:00

Never mind - found the error (why does this always happen?).

I was using a pipe symbol rather than lower-case letter L, so I had:

.Text = "^|"

when it should have been:

.Text = "^l"

That's what comes of reading code examples off the web in a sans-serif typeface!

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2012-11-14T10:03:46+00:00

    If it makes you feel better, when I looked at your code, I didn't see it either :-)

    Cheers

    Was this answer helpful?

    0 comments No comments