#1
|
|||
|
|||
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 |
#2
|
|||
|
|||
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 |
#3
|
|||
|
|||
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? |
|
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 |
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 |