![]() |
|
#1
|
|||
|
|||
![]()
Jay,
Okay. The problem here is that you have shown no code to change or review. As you have studied previous examples, you should at least have code in the ThisDocument module Document_ContentContorlOnExit event which triggers on CC Exit and evaluates which of the seven selections you made. Here, I assume you have a dropdown list titled "DDL" which contains four entires "A,B,C and D" When one of those are selected we call a variation of the procedure I posted earlier to populate both a named range at a document rich text content control titled "Conditional Content" and a named range at a document bookmarked titled "bmConditionalContent" Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Select Case ContentControl.Title Case "DDL" Select Case ContentControl.Range.Text Case "A": InsertBB_atRTCC_Range "Conditional Content", "Text1": InsertBB_atBookmarkRange_Range "bmConditionalContent", "Text1" Case "B": InsertBB_atRTCC_Range "Conditional Content", "Text2": InsertBB_atBookmarkRange_Range "bmConditionalContent", "Text2" Case "C" Case "D" '...so on. Case Else: InsertBB_atRTCC_Range "Conditional Content": InsertBB_atBookmarkRange_Range "bmConditionalContent" End Select End Select lbl_Exit: Exit Sub End Sub Sub InsertBB_atRTCC_Range(CCTitle As String, Optional BBName As String = vbNullString) Dim oTmp As Template Dim oRng As Range Set oTmp = NormalTemplate Set oRng = ActiveDocument.SelectContentControlsByTitle(CCTitle).Item(1).Range If Not BBName = vbNullString Then oTmp.BuildingBlockEntries(BBName).Insert oRng, True Else oRng.Text = vbNullString End If lbl_Exit: Exit Sub End Sub Sub InsertBB_atBookmarkRange_Range(BMName As String, Optional BBName As String) Dim oTmp As Template Dim oRng As Range Set oTmp = NormalTemplate Set oRng = ActiveDocument.Bookmarks(BMName).Range If Not BBName = vbNullString Then Set oRng = oTmp.BuildingBlockEntries(BBName).Insert(oRng, True) Else oRng.Text = vbNullString End If ActiveDocument.Bookmarks.Add BMName, oRng lbl_Exit: Exit Sub End Sub |
#2
|
|||
|
|||
![]()
Thanks for your reply, I appreciate the clarification. The title of my dropdown is "Trigger Statements", with a dropdown entry titled "SAS". When SAS is selected from the dropdown I want it to populate a building block from the autotext gallery in the general category which was saved and named as "SASText". Is the below code the correct way to implement that?
Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean) Select Case ContentControl.Title Case "Trigger Statements" Select Case ContentControl.Range.Text Case "SAS": InsertBB_atRTCC_Range "Conditional Content", "SASText": InsertBB_atBookmarkRange_Range "bmConditionalContent", "SASText" Case Else: InsertBB_atRTCC_Range "Conditional Content": InsertBB_atBookmarkRange_Range "bmConditionalContent" End Select End Select lbl_Exit: Exit Sub End Sub Sub InsertBB_atRTCC_Range(CCTitle As String, Optional BBName As String = vbNullString) Dim oTmp As Template Dim oRng As Range Set oTmp = NormalTemplate Set oRng = ActiveDocument.SelectContentControlsByTitle(CCTitle).Item(1).Range If Not BBName = vbNullString Then oTmp.BuildingBlockEntries(BBName).Insert oRng, True Else oRng.Text = vbNullString End If lbl_Exit: Exit Sub End Sub Sub InsertBB_atBookmarkRange_Range(BMName As String, Optional BBName As String) Dim oTmp As Template Dim oRng As Range Set oTmp = NormalTemplate Set oRng = ActiveDocument.Bookmarks(BMName).Range If Not BBName = vbNullString Then Set oRng = oTmp.BuildingBlockEntries(BBName).Insert(oRng, True) Else oRng.Text = vbNullString End If ActiveDocument.Bookmarks.Add BMName, oRng lbl_Exit: Exit Sub End Sub |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
angelaschultz | Word VBA | 7 | 03-18-2017 03:00 PM |
![]() |
GregStewartPTC | Word VBA | 2 | 02-27-2017 05:37 AM |
![]() |
vera | Word VBA | 1 | 10-07-2016 07:41 PM |
VBA Word - Building Block (AutoText) - Array - Replace Text with Specific Building Blocks | jc491 | Word VBA | 7 | 01-03-2016 10:34 PM |
Building blocks show correctly in dropdown, but wrong building block populates in doc | wordgirl123 | Word | 0 | 10-03-2013 08:30 AM |