View Single Post
 
Old 02-04-2014, 06:53 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
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

Your code suggests you want to toggle the bold attribute for 'Synopsis' in the 'Body Text' Style, not simply make it all bold or all not bold. In that case, you could use a macro like:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim Rng As Range
With Selection
  Set Rng = .Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "Synopsis"
    .Replacement.Text = "^&"
    .Style = "Body Text"
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = True
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  Do While .Find.Found
    .Font.Bold = wdToggle
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Rng.Select
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
If, however, you wish to make all such text bold, the macro could be made much more efficient and simplified to:
Code:
Sub Demo()
Application.ScreenUpdating = False
With Selection
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "Synopsis"
    .Replacement.Text = "^&"
    .Style = "Body Text"
    .Replacement.Font.Bold = True
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = True
    .MatchWholeWord = True
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
If you want to make the font not bold instead, change:
.Replacement.Font.Bold = True
to:
.Replacement.Font.Bold = False
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote