Reputation: 39
I'm trying to make sure the dates stay together and not break across lines.
The replacement text should have two non breaking spaces, one between \1 April, and one between April \2.
Sub SarahDates()
‘ Supposed to put a non breaking space between day, month and year.
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = “([0-9]) April ([0-9])”
.Replacement.Text = “\1 April \2”
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
What is the correct text in .Replacement.Text
so that non-breaking spaces are shown in macro.
Upvotes: 0
Views: 304
Reputation: 13490
the following macro will reformat all your dates in one go.
Sub SarahDates()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "(<[0-9]{1,2}) ([JFMASOND][abceghilmnoprstuvy]{2,8}) ([12][0-9]{3}>)"
.Replacement.Text = "\1^s\2^s\3"
.Forward = True
.Format = False
.Wrap = wdFindContinue
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
Upvotes: 1