Log in

View Full Version : RichText content control anomoly



gmaxey
11-09-2022, 01:25 PM
This is an observation that I wanted to share (not a question). While working on a project today, I discovered that you can't insert a buildingblock containing multiple paragraphs in a document richtext content control unless that content control is the unique element in a paragraph.

To illustrate,

1. I created a building block "ML" containing multiple paragraphs
2. I added a richtext content control titled "shareline" to a paragraph containing a few words i.e., "Test, test: richtextCC"
3. I added a richtext content control titled "devotedline" to an empty paragraph

I ran the following code:


Sub DemoIssue()
Dim oCC1 As ContentControl
Dim oCC2 As ContentControl
Dim oDoc As Document
Set oDoc = ActiveDocument
Set oCC1 = oDoc.SelectContentControlsByTitle("shareline").Item(1) 'error occurs
Set oCC2 = oDoc.SelectContentControlsByTitle("devotedline").Item(1)
On Error GoTo Err_Handler
oDoc.AttachedTemplate.BuildingBlockEntries("ML").Insert oCC1.Range
oDoc.AttachedTemplate.BuildingBlockEntries("ML").Insert oCC2.Range
lbl_exit:
Exit Sub
Err_Handler:
If Err.Number = -2147467259 Then
MsgBox "You cannot insert a building block containing multiple paragraphs into a richtext content " _
& "control unless that content control is the unique content of a paragraph.", vbInformation + vbOKOnly, "INVALID ACTION"
End If
Resume Next
End Sub

This is not just a VBA anomaly. If you try to insert a buildingblock containing multiple paragraphs from Insert>QuickParts>BuildingBlock Organizer into a richtext control not by itself in a paragraph, you get nothing inserted. If you try to copy and paste multiple paragraphs into to a richtext CC not by itself, the paragraphs are stripped out of the content pasted.

Aussiebear
11-09-2022, 02:01 PM
So it becomes an order of hierarchy then in order for you to proceed?

gmaxey
11-09-2022, 02:20 PM
The demo was just to show that you can't insert a multiline BB in a richtext control if that control is part of other text in the paragraph (oCC1) while you can in a richtext CC that is the only content in a paragraph (oCC2)