View Single Post
 
Old 11-15-2013, 07:09 PM
jamles12 jamles12 is offline Windows 8 Office 2007
Novice
 
Join Date: Nov 2013
Posts: 5
jamles12 is on a distinguished road
Default

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