Hello Greg,
thank you for your answer, but the macro does not work, the debugger notifies me of an error I cannot identify.
However, you helped me with the construction. I managed to solve the problem like this:
Sub ReplaceLitres()
'
' nbsp between number and unit (l)
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([0-9]) (l[!a-z])"
.Replacement.Text = "\1^s\2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([0-9])(l[!a-z])"
.Replacement.Text = "\1^s\2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
I know it is not very elegant and subtle solution, but it works. I have problem with grasping the repeating problem. When I try to use one replacing with the following:
...
.Text = "([0-9])([ ]{0,1})(l[!a-z])"
.Replacement.Text = "\1^s\3"
...
the macro does nothing. Why can I use [0-9], [!a-z] but not the range [ ]{0,1} feature?