View Single Post
 
Old 12-03-2023, 11:02 PM
Guessed's Avatar
Guessed Guessed is online now Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,177
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

Try this version
Code:
Sub B_A_RemoveRT_ExceptMe()
  Dim i As Integer, oCC As ContentControl, sTag As String
  
  For i = ActiveDocument.ContentControls.Count To 1 Step -1
    Set oCC = ActiveDocument.ContentControls(i)
    If oCC.Type = wdContentControlRichText Then
      sTag = " " & oCC.Tag & " "
      If InStr(sTag, " Me ") > 0 Then
        oCC.LockContentControl = False
        oCC.Range.Bookmarks("\Page").Range.Delete
      End If
    End If
  Next i
lbl_Exit:
  Exit Sub
End Sub
Note that there are scenarios where you might see unintended results - such as you delete a section break which changes page setups and therefore page content gets deleted that you didn't think about. Also, if the Rich Text Content Control spans across a page then I would expect an error or only some of its contents getting deleted.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote