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.
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.