Hello,
New in vba. I search to insert very simply a building block from quickpart inside my word document but I can't. I have find the classical VBA code :
Code:
Sub InsertExistingBuildingBlock()
Dim objTemplate As Template
Dim objBB As BuildingBlock
' Set the template to store the building block
Set objTemplate = ActiveDocument.AttachedTemplate
' Access the building block through the type and category
Set objBB = objTemplate.BuildingBlockTypes(wdTypeCustomHeaders) _
.Categories("Book Titles").BuildingBlocks("Title")
' Insert the building block into the document replacing any selected
text.
objBB.Insert Selection.Range
End Sub
But it is not working.
Another link advices to load preliminary the templates with :
Templates.LoadBuildingBlocks
I do it and I have try this following code :
Code:
Sub InsertExistingBuildingBlock()
Dim objTemplate As Template
Dim objBB As BuildingBlock
' Set the template to store the building block
Set objTemplate = ActiveDocument.AttachedTemplate
' Access the building block through the type and category
Set objBB = objTemplate.BuildingBlockTypes(Bibliographies) _
.Categories("Prédifini").BuildingBlocks("Travaux cités")
' Insert the building block into the document replacing any selected
text.
objBB.Insert Selection.Range
End Sub
But it is not working
I have try this folowing code to indicate the way of the file building blocks.dotx
Code:
Sub TestBuildingBlocks()
Templates.LoadBuildingBlocks ' chargement du template building blocks
Templates("C:\Utilisateur\ utilisateur\AppData\Roaming\Microsoft\Document Building Blocks\1036\Building Blocks.dotx"). _
BuildingBlockTypes("bibliography").Categories("Prédéfini").BuildingBlocks("Travaux cités").Insert Where:=Selection.Range
End Sub
It doesn't work !
Could you please help me to insert a building block from quickparts. I enclosed 2 images from the templates and the quickparts content.
I need your help,
Thank you very much,
sincerely
jasserin