![]() |
|
#1
|
||||
|
||||
![]()
With a combobox content control, title it GetBlock (or whatever) then in the
Insert a bookmark where you want the building block to be placed (say bmBlock) Add the following code to a new module in the document project Code:
Public Sub BBToBM(strBMName As String, strTemplate As String, strBBName As String) Option Explicit 'Graham Mayor - http://www.gmayor.com Dim oRng As Range Dim iLen1 As Integer, iLen2 As Integer With ActiveDocument iLen1 = Len(ActiveDocument.Range) On Error GoTo lbl_Exit Set oRng = .Bookmarks(strBMName).Range Application.Templates(strTemplate). _ BuildingBlockEntries(strBBName).Insert _ Where:=oRng, _ RichText:=True iLen2 = Len(ActiveDocument.Range) oRng.End = oRng.End + (iLen2 - iLen1) oRng.Bookmarks.Add strBMName End With lbl_Exit: Set oRng = Nothing Exit Sub End Sub Code:
Option Explicit Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) If ContentControl.Title = "GetBlock" Then Select Case ContentControl.Range.Text Case "Item1" BBtoBM "bmBlock", "D:\Word 2016 Templates\Normal.dotm", "BB Name 1" Case "Item2" BBtoBM "bmBlock", "D:\Word 2016 Templates\Normal.dotm", "BB Name 2" End Select End If End Sub Save as a macro enabled document (or template). Change any of the names and paths involved to fit what you have.
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#2
|
|||
|
|||
![]() Quote:
Ive been working on the IF method. I roughly know how to do it this way. The only thing I am missing is how do I relate to a combo box within a field formula? |
#3
|
|||
|
|||
![]() Quote:
Did you look at the tutorial on field maths? |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
duncan_bridge@hotmail.com | Word | 3 | 07-22-2016 01:38 AM |
![]() |
houseofturner | Word | 4 | 07-19-2016 07:24 AM |
VBA Word - Building Block (AutoText) - Array - Replace Text with Specific Building Blocks | jc491 | Word VBA | 7 | 01-03-2016 10:34 PM |
![]() |
EGoetz | Word VBA | 2 | 12-05-2013 09:09 PM |
Building blocks show correctly in dropdown, but wrong building block populates in doc | wordgirl123 | Word | 0 | 10-03-2013 08:30 AM |