gmaxey
04-12-2017, 04:59 AM
I created and saved two simple buildingblocks in my normal template Custom Gallery 4 in new "Test" category:
"Underlined text and plain text" - Named "Underlined"
"Bold text and plain text" - Named "Bold"
I then entered a building block ContentControl to the document and set it to filter and display Custom Galley 4 Test category building blocks an titled it "Test". Using this CC and the its dropdown interface, I can select and display either the Underline or Bold building block in the document.
I would like to be able to select and display the appropriate buildingblock in the control using VBA, e.g.,:
If 1 = 1 Then
Control display Underline (or control display item 2)
Else
Control display Bold (or control display item 1)
End If
I don't see any methods of the contentcontrol that supports this (i.e., item(1).select)
As a work around, I tried this
Sub Demo()
Dim oCC As ContentControl
Set oCC = ActiveDocument.SelectContentControlsByTitle("Test").Item(1)
Set oRng = oCC.Range
NormalTemplate.BuildingBlockTypes(wdTypeCustom4).Categories("Test").BuildingBlocks("Bold").Insert oRng, True
NormalTemplate.BuildingBlockTypes(wdTypeCustom4).Categories("Test").BuildingBlocks("Underlined").Insert oRng, True
End Sub
That worked (sort of), but the problem was after the code runs, the "entire" text of the content control is bold and underlined. Tweaking a little, I've got this which works but seems clunky.
Sub Demo()
Dim oRng As Word.Range
Dim oCC As ContentControl
Set oCC = ActiveDocument.SelectContentControlsByTitle("Test").Item(1)
Set oRng = oCC.Range
oRng.Font.Reset
NormalTemplate.BuildingBlockTypes(wdTypeCustom4).Categories("Test").BuildingBlocks("Bold").Insert oRng, True
oRng.Font.Reset
NormalTemplate.BuildingBlockTypes(wdTypeCustom4).Categories("Test").BuildingBlocks("Underlined").Insert oRng, True
End Sub
Has anyone found a better way programmatically select and display a buildingblock galley content control building block?
Thanks.
"Underlined text and plain text" - Named "Underlined"
"Bold text and plain text" - Named "Bold"
I then entered a building block ContentControl to the document and set it to filter and display Custom Galley 4 Test category building blocks an titled it "Test". Using this CC and the its dropdown interface, I can select and display either the Underline or Bold building block in the document.
I would like to be able to select and display the appropriate buildingblock in the control using VBA, e.g.,:
If 1 = 1 Then
Control display Underline (or control display item 2)
Else
Control display Bold (or control display item 1)
End If
I don't see any methods of the contentcontrol that supports this (i.e., item(1).select)
As a work around, I tried this
Sub Demo()
Dim oCC As ContentControl
Set oCC = ActiveDocument.SelectContentControlsByTitle("Test").Item(1)
Set oRng = oCC.Range
NormalTemplate.BuildingBlockTypes(wdTypeCustom4).Categories("Test").BuildingBlocks("Bold").Insert oRng, True
NormalTemplate.BuildingBlockTypes(wdTypeCustom4).Categories("Test").BuildingBlocks("Underlined").Insert oRng, True
End Sub
That worked (sort of), but the problem was after the code runs, the "entire" text of the content control is bold and underlined. Tweaking a little, I've got this which works but seems clunky.
Sub Demo()
Dim oRng As Word.Range
Dim oCC As ContentControl
Set oCC = ActiveDocument.SelectContentControlsByTitle("Test").Item(1)
Set oRng = oCC.Range
oRng.Font.Reset
NormalTemplate.BuildingBlockTypes(wdTypeCustom4).Categories("Test").BuildingBlocks("Bold").Insert oRng, True
oRng.Font.Reset
NormalTemplate.BuildingBlockTypes(wdTypeCustom4).Categories("Test").BuildingBlocks("Underlined").Insert oRng, True
End Sub
Has anyone found a better way programmatically select and display a buildingblock galley content control building block?
Thanks.