Reputation: 50
I have a content control that already contains text. I want to add new text, and put the previous text in StrikeThrough, my code looks like this.
Sub testCCrangeModifier()
Dim CC As ContentControl
For Each CC In ActiveDocument.ContentControls
If CC.Title = "myContentControl" And CC.Tag = "myContentControl" Then
CC.Range.Font.StrikeThrough = True
CC.Range.Text = ("NEWTEXT" & Chr(13) & Chr(10) & CC.Range.Text)
End If
Next CC
End Sub
With this code, the result is:
NEWTEXT
OLDTEXT
The result should look like this
Before the macro:
OLDTEXT
After the macro:
NEWTEXT
OLDTEXT
Chr(13) & Chr(10) is the linebreak between the oldtext and newtext
Upvotes: 0
Views: 273
Reputation: 7850
The code below checks that CC
is a rich text content control, then adds the text and removes strikethrough from the first paragraph.
Sub testCCrangeModifier()
Dim CC As ContentControl
For Each CC In ActiveDocument.ContentControls
If CC.Title = "myContentControl" And CC.Tag = "myContentControl" And CC.Type = wdContentControlRichText Then
With CC.Range
.Font.StrikeThrough = True
.Text = ("NEWTEXT" & Chr(13) & Chr(10) & CC.Range.Text)
.Paragraphs(1).Range.Font.StrikeThrough = False
End With
End If
Next CC
End Sub
Upvotes: 1