Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-23-2024, 05:32 AM
MulaMuster MulaMuster is offline Listbox with available Building Blocks to choose from Windows 11 Listbox with available Building Blocks to choose from Office 2021
Novice
Listbox with available Building Blocks to choose from
 
Join Date: May 2024
Posts: 1
MulaMuster is on a distinguished road
Question Listbox with available Building Blocks to choose from

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.
Reply With Quote
  #2  
Old 05-23-2024, 02:29 PM
gmaxey gmaxey is offline Listbox with available Building Blocks to choose from Windows 10 Listbox with available Building Blocks to choose from Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,602
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Tags
building block, listbox, word vba



Similar Threads
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

Other Forums: Access Forums

All times are GMT -7. The time now is 10:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft