![]() |
|
#1
|
|||
|
|||
![]()
Hi there, I'm struggeling with the following.
I have a Word form with a listbox. I fill this listbox with the available Building Blocks in the template. I wan't to multichoose the items in the listbox and select insert so selected Building Blocks are added to the document. The template with the building blocks and the form is stored on SharePoint using Content Types so i can select this template to start from Sharepoint. It works but not as i want it to work and can't figure it out. Private Sub cmdList_Click() Dim objTemplate As Template Dim objBB As BuildingBlock Set objTemplate = ThisDocument.AttachedTemplate With lstFoundBBs For i = 0 To .ListCount - 1 If .Selected(i) Then Set objBB = objTemplate.BuildingBlockEntries(lstFoundBBs.Value ) objBB.Insert Selection.Range End If Next i End With Exit For End Sub Keeping error on objTemplate.BuildingBlockEntries(lstFoundBBs.Value ). If I choose objTemplate.BuildingBlockEntries(1) it takes the first Building Block so I need to translate number 1 from the listbox. I need this to work for all categories. As alternative I tried the follwing: Set oBB = Application.Templates(sTempName).BuildingBlockType s(wdTypeAutoText).Categories.Item("MMW").BuildingB locks(sBBName) I need the Categories.Item("MMW") to be dynamic and working for all categories. Any help on this will be appreciated. Thanks. |
#2
|
|||
|
|||
![]() Code:
Private Sub UserForm_Initialize() Dim objTemplate As Template Dim objBB As BuildingBlock Dim lngBB As Long Set objTemplate = ThisDocument.AttachedTemplate For lngBB = 1 To objTemplate.BuildingBlockEntries.Count Set objBB = objTemplate.BuildingBlockEntries(lngBB) With ListBox1 .AddItem .List(.ListCount - 1, 0) = objBB.Name .List(.ListCount - 1, 1) = objBB.Category.Name .List(.ListCount - 1, 2) = objBB.Type.Index End With Next End Sub Private Sub CommandButton1_Click() Dim objTemplate As Template Dim objBB As BuildingBlock Dim i As Long Set objTemplate = ThisDocument.AttachedTemplate With ListBox1 For i = 0 To .ListCount - 1 If .Selected(i) Then Set objBB = objTemplate.BuildingBlockTypes(.List(i, 2)).Categories(.List(i, 1)).BuildingBlocks(.List(i, 0)) objBB.Insert Selection.Range End If Next i End With End Sub |
![]() |
Tags |
building block, listbox, word vba |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Building blocks | NorbertM | Word | 5 | 11-22-2019 11:25 AM |
VBA Word - Building Block (AutoText) - Array - Replace Text with Specific Building Blocks | jc491 | Word VBA | 7 | 01-03-2016 10:34 PM |
Sharing Building Blocks | dricciuti | Word | 0 | 11-03-2013 03:40 PM |
Building blocks show correctly in dropdown, but wrong building block populates in doc | wordgirl123 | Word | 0 | 10-03-2013 08:30 AM |
Building Blocks - WHY??? | namedujour | Word | 5 | 05-03-2011 01:37 PM |