Forum Discussion
templatebuilding
Magnus_Edstrm If you had the list entries A, B, C, etc in a Combobox Content Control in the document and you enclose the Form corresponding to each entry in a bookmark A, B, C, etc and you have the following code in the ThisDocument object, when an item is selected in the combobox and the user exits from that combobox, only the form corresponding to the selected item will be visible and the forms corresponding to the other list entries will be hidden.
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl
If .Title = "ALPHA" Then
For i = 1 To .DropdownListEntries.Count
If ActiveDocument.Bookmarks.Exists(.DropdownListEntries(i).Text) Then
ActiveDocument.Bookmarks(.DropdownListEntries(i).Text).Range.Font.Hidden = True
End If
Next i
For i = 1 To .DropdownListEntries.Count
If .DropdownListEntries(i) = .Range.Text Then
ActiveDocument.Bookmarks(.DropdownListEntries(i).Text).Range.Font.Hidden = False
End If
Next i
End If
End With
End Sub
- Magnus_EdstrmDec 19, 2022Copper Contributor
This is exactly what I am after. Where do I insert this line of code? and where do I change the value to correspond with the item in the combobox content control?
/Magnus
- Dec 19, 2022
Magnus_Edstrm You should create a macro enabled template (*.dotm) and in the Visual Basic Editor, access the ThisDocument object and paste the code into the Window on the right
The code has been written on the basis that the items in the combobox are identical to the bookmarks in the template so that it is not necessary to refer either to the actual items in the list or to the actual bookmark names and also so that the code will cater for any number of items in the list\bookmarks in the document.
Start by using your examples of A, B, and C to see for yourself that it works.
- Magnus_EdstrmDec 20, 2022Copper Contributor
I am not having success (or I just botched it)
This is what the word-document looks like