View Single Post
 
Old 11-25-2018, 01:14 AM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,184
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The code stumbled over something odd in those docs. I adjusted the code and this appears to work on both those samples. I added applying a character style which will make life a lot easier in the future.
Code:
Sub GroupTags()
  Dim aRng As Range, aCC As ContentControl
  
  ActiveDocument.Styles("Intense Emphasis").Font.Color = wdColorGray50
  
  'Clear all CCs
  For Each aCC In ActiveDocument.ContentControls
    aCC.Delete
  Next aCC
  
  Set aRng = ActiveDocument.Range(0, 0)
  With aRng.Find
    .ClearFormatting
    .Font.Color = wdColorGray50
    .Replacement.ClearFormatting
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
    Do While .Execute
      aRng.Select     'not necessary unless troubleshooting
      If aRng.ContentControls.Count = 0 Then
        aRng.Style = "Intense Emphasis"
        aRng.ContentControls.Add (wdContentControlGroup)
      End If
      aRng.Collapse Direction:=wdCollapseEnd
    Loop
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote