View Single Post
 
Old 12-13-2016, 07:34 AM
lukegwilson96 lukegwilson96 is offline Windows 7 32bit Office 2010 32bit
Novice
 
Join Date: Dec 2016
Posts: 4
lukegwilson96 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
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
In the ThisDocument module of the active document project add the following. Change the template from "D:\Word 2016 Templates\Normal.dotm" to the full path of wherever the building blocks (here BB Name 1 and BB Name 2) are stored.

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
Then if you have two entries in the combobox = Item1 and Item2, when you leave the combo box having made your selection, the appropriate building block is written to the bookmark.

Save as a macro enabled document (or template). Change any of the names and paths involved to fit what you have.
Hi Thank you,

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?
Reply With Quote