View Single Post
 
Old 02-08-2017, 06:53 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Greg's posted one way, here's another:
Code:
Sub Demo()
Application.ScreenUpdating = False
ActiveWindow.View.ShowFieldCodes = True
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "Section ^d"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    .Execute
  End With
  Do While .Find.Found
    With .Fields(1)
      With .Code
        If InStr(.Text, "Mergeformat") > 0 Then
          .Text = Replace(.Text, "Mergeformat", "Charformat")
        ElseIf InStr(.Text, "Charformat") = 0 Then
          .InsertAfter " \* Charformat"
        End If
        .Words.First.Next.Style = "Emphasis"
      End With
      .Update
    End With
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
ActiveWindow.View.ShowFieldCodes = False
Application.ScreenUpdating = True
End Sub
My code's more robust...
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote