Thread: [Solved] Help, please, with macro bug
View Single Post
 
Old 02-18-2022, 04:47 PM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The reason nothing happens is simple: your first 'Find' expression simply configures Word to find the first instance of a space before an em-dash - but then does nothing. Your second 'Find' expression then tries to find a space after an em-dash in the same selection. There is also no need for the parentheses.

Try:
Code:
Sub Ems()
Application.ScreenUpdating = False
With ActiveDocument.Range.Find
  .ClearFormatting
  .Replacement.ClearFormatting
  .Format = False
  .Forward = True
  .Wrap = wdFindContinue
  .MatchWildcards = False
  .Replacement.Text = "^+"
  .Text = " ^+"
  .Execute Replace:=wdReplaceAll
  .Text = "^+ "
  .Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote