|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
how to make building block content control determine bb to display elsewhere
I have a building block content control that has specific building blocks and I would like to have my template place a picture somewhere in the document based on which building block I choose. Any help would be greatly appreciated!
|
#2
|
|||
|
|||
Is your building block the picture or a choice? And then the choice determines which picture? Does it also determine the location?
|
#3
|
|||
|
|||
I have a building block content control with about 6 different choices of building blocks and depending on which building block determines which picture is displayed on the cover page so the picture is always is the same position. I actually got it sort of working by placing a bookmark and then using autotext building blocks with the code below. The problem is that it is looking for a specific word in the autotext to work so in other words since the below code looks for case Apple in the contentcontrol.range.text it only works if the original buildingblock contains the word Apple and only the word Apple! Im sure that I just need to change the ContentControl.Range.Text to something that would just look at the name of the buildingblock but I dont know how to so any help would mean a ton to me right now. Thank you for looking.
Code:
Dim oRng As Word.Range Select Case ContentControl.Title Case "Fruit" Select Case ContentControl.Range.Text Case "Apple" InsertBBEinBM "Fruit", "Apple" Case "Orange" InsertBBEinBM "Fruit", "Orange" Case "Pear" InsertBBEinBM "Fruit", "Pear" Case Else InsertBBEinBM "Fruit", " " End Select End Select lbl_Exit: Exit Sub End Sub Sub InsertBBEinBM(ByRef pBMTarget As String, pBBEName As String) Dim oRng As Word.Range With ActiveDocument Set oRng = .Bookmarks(pBMTarget).Range If Not pBBEName = " " Then Set oRng = .AttachedTemplate.BuildingBlockTypes(wdTypeAutoText).Categories("Fruit") _ .BuildingBlocks(pBBEName).Insert(oRng, True) Else oRng.Text = "" End If .Bookmarks.Add pBMTarget, oRng End With lbl_Exit: Exit Sub End Sub |
#4
|
|||
|
|||
Try changing your second select statement to:
Select Case True Case InStr(ContentControl.Range.Text, "apple") > 0 Of course "apple" (and the word you use in the other case statements) must be unique. |
#5
|
|||
|
|||
That gets me much closer thanks! but is there anyway to choose it by the name of the building block instead of text within it?
|
#6
|
|||
|
|||
"...but is there anyway to choose it by the name of the building block instead of text within it?"
Not that I can find. The content control has a BuildingBlockType and Category Property but there is nothing that returns the name of the building blocks are the building block selected. |
Tags |
help please, macro, macropod |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Deleting a table from a content control -- preserving the content control | BrainSlugs83 | Word Tables | 8 | 11-14-2013 03:06 AM |
Content control problem | Anja | Word | 2 | 10-16-2013 09:56 AM |
Building blocks show correctly in dropdown, but wrong building block populates in doc | wordgirl123 | Word | 0 | 10-03-2013 08:30 AM |
Hierarchical content control | ntjson | Word VBA | 1 | 04-04-2013 12:07 AM |
Retrieving content control value | jillapass | Word VBA | 4 | 05-24-2012 05:07 AM |