Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-30-2023, 10:33 AM
aj92 aj92 is offline Delete Rich Text by Tag Mac OS X Delete Rich Text by Tag Office 2021
Novice
Delete Rich Text by Tag
 
Join Date: Nov 2023
Posts: 9
aj92 is on a distinguished road
Default Delete Rich Text by Tag

Is there a way to write a macro that does this:


Delete all rich text content control along with the text inside of the rich text content control that doesn't contain the word "Me" in it


--




I'm hoping with this macro I'll be able to delete all text wrapped in rich text that does not have the word "Me" in its tag. Similarly, rich text that is tagged like this as an example, "Assistant 1 and Me", would not be deleted either since "Me" is listed in the tag




Thanks for your time
Reply With Quote
  #2  
Old 12-01-2023, 04:07 AM
gmaxey gmaxey is offline Delete Rich Text by Tag Windows 10 Delete Rich Text by Tag Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim oCC As ContentControl
Dim arrTagParts() As String
Dim lngIndex As Long
Dim bDelete As Boolean
  
  For Each oCC In ActiveDocument.ContentControls
    bDelete = True
    If oCC.Type = 0 Then
      arrTagParts = Split(oCC.Tag, " ")
      For lngIndex = 0 To UBound(arrTagParts)
        If arrTagParts(lngIndex) = "Me" Then
          bDelete = False
          Exit For
        End If
      Next lngIndex
      If bDelete Then oCC.Delete True
   End If
 Next oCC
lbl_Exit:
  Exit Sub
  
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 12-01-2023, 06:16 PM
aj92 aj92 is offline Delete Rich Text by Tag Windows 11 Delete Rich Text by Tag Office 2021
Novice
Delete Rich Text by Tag
 
Join Date: Nov 2023
Posts: 9
aj92 is on a distinguished road
Default

Thanks so much! This is SO close to working. The only problem I'm seeing is that any rich text that contains "Me" in it is deleting the text inside the rich text content control box. I want that to be preserved


Is that possible to do?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy Formatted Text in one Rich Text Content Control to another Rich Text Content Control Haygordon Word 1 04-05-2019 05:43 AM
Delete Rich Text by Tag Rich text/Plain text Content Controls in Template michael.fisher5 Word 9 11-19-2014 06:36 AM
Retrieving Rich Text from a RTF Text box in a User Form jpb103 Word VBA 14 06-23-2014 08:45 AM
My plain text post got converted to rich text in a reply, how to convert it back? david.karr Outlook 0 01-05-2012 09:46 AM
Templates: automatic text generation from Rich Text content control Chickenmunga Word 0 10-01-2008 11:16 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft