Link to home
Start Free TrialLog in
Avatar of TexasEx95
TexasEx95

asked on

run-time error 5624 on Find/Replace Line

I found this macro code to replace tab spacing with a single space, but I get a run-time 5624 error. The debugger highlights the following line as having the problem:

Selection.Find.Replacement.ClearFormatting

Please help! Getting this macro to run will save me an enormous amount of time!

Sub TabsOut()
    If Selection.Type <> wdNoSelection Then
        Selection.HomeKey Unit:=wdStory, Extend:=wdMove
    End If
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p^t"
        .Replacement.Text = "^p^"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of EDDYKT
EDDYKT
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TexasEx95
TexasEx95

ASKER

Thank you! I was also able to modify the macro and make two new ones based on your solution. You have saved me countless hours of formatting!