Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-13-2016, 03:18 AM
lukegwilson96 lukegwilson96 is offline Quick part building blocks - Formula Windows 7 32bit Quick part building blocks - Formula Office 2010 32bit
Novice
Quick part building blocks - Formula
 
Join Date: Dec 2016
Posts: 4
lukegwilson96 is on a distinguished road
Default Quick part building blocks - Formula


Can you use formulas to insert quick part building blocks?

For example if drop down box equals 'a' insert building block '1'
Reply With Quote
  #2  
Old 12-13-2016, 03:47 AM
gmayor's Avatar
gmayor gmayor is offline Quick part building blocks - Formula Windows 10 Quick part building blocks - Formula Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

You can with a macro. What sort of 'dropdown box' did you have in mind?
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 12-13-2016, 05:24 AM
Charles Kenyon Charles Kenyon is offline Quick part building blocks - Formula Windows 10 Quick part building blocks - Formula Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

You also can do it with an IF Field and an AutoText field or building block content control as the truetext or falsetext. It depends on the building block.

See Microsoft Word Field Maths Tutorial. This does not require a macro but it is not necessarily easy.
Reply With Quote
  #4  
Old 12-13-2016, 06:13 AM
lukegwilson96 lukegwilson96 is offline Quick part building blocks - Formula Windows 7 32bit Quick part building blocks - Formula Office 2010 32bit
Novice
Quick part building blocks - Formula
 
Join Date: Dec 2016
Posts: 4
lukegwilson96 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
You can with a macro. What sort of 'dropdown box' did you have in mind?
Combo box content control
Reply With Quote
  #5  
Old 12-13-2016, 07:10 AM
gmayor's Avatar
gmayor gmayor is offline Quick part building blocks - Formula Windows 10 Quick part building blocks - Formula Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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.
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #6  
Old 12-13-2016, 07:34 AM
lukegwilson96 lukegwilson96 is offline Quick part building blocks - Formula Windows 7 32bit Quick part building blocks - Formula Office 2010 32bit
Novice
Quick part building blocks - Formula
 
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
  #7  
Old 12-13-2016, 10:46 AM
Charles Kenyon Charles Kenyon is offline Quick part building blocks - Formula Windows 10 Quick part building blocks - Formula Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by lukegwilson96 View Post
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?
Study the IF field's structure. You need something to test. If it is the combo box, that needs to be bookmarked.

Did you look at the tutorial on field maths?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Quick part building blocks - Formula Deleted 'Built In' Quick Part Building Blocks by accident! duncan_bridge@hotmail.com Word 3 07-22-2016 01:38 AM
Quick part building blocks - Formula Building Blocks / Quick Parts 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
Quick part building blocks - Formula Word 2013: Building Blocks / Quick Parts - Form Question 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

Other Forums: Access Forums

All times are GMT -7. The time now is 09:15 AM.


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