Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-31-2020, 09:10 PM
chriscla chriscla is offline Multiple entries in dropdown lists with building blocks Windows 10 Multiple entries in dropdown lists with building blocks Office 2013
Novice
Multiple entries in dropdown lists with building blocks
 
Join Date: Mar 2020
Posts: 18
chriscla is on a distinguished road
Default Multiple entries in dropdown lists with building blocks

Hi




In his thread (https://www.msofficeforums.com/word-...own-lists.html) Paul gave a solution to have a control content filled with text after a listbox choice. This works great for small texts.


For larger texts (multiple paragraphs) this doesn't work unfortunately.
Linking the choice of the listbox to building blocks should work, but I have no idea how to achieve this. I have the building blocks, I have a building block content control, but I have no link to the list box.


Any help is more than welcome.


Chris
Reply With Quote
  #2  
Old 04-01-2020, 01:18 AM
gmayor's Avatar
gmayor gmayor is offline Multiple entries in dropdown lists with building blocks Windows 10 Multiple entries in dropdown lists with building blocks Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 could use a simple function to fill a rich text content control with the formatted text from the autotext entry, according to the value selected in the list box (see attached template) e.g. as follows - Create a new document from the template


Code:
Sub AutoTextToCC(strCCName As String, oTemplate As Template, strAutotext As String)
'Graham Mayor - https://www.gmayor.com - Last updated - 10 Apr 2019
'strCCName is the ContentControl title
'oTemplate is the template with the autotext entry
'strAutotext is the name of the autotext entry
Dim oCC As ContentControl
    On Error GoTo lbl_Exit
    For Each oCC In ActiveDocument.ContentControls
        If oCC.TITLE = strCCName Then
            oCC.LockContentControl = True
            oTemplate.AutoTextEntries(strAutotext).Insert Where:=oCC.Range, RichText:=True
            Exit For
        End If
    Next oCC
lbl_Exit:
    Exit Sub
End Sub

You may find Insert Content Control Add-In useful for entering and/or modifying the content controls.
Attached Files
File Type: dotm Content Controls - Dropdown Dependent Text.dotm (40.3 KB, 25 views)
__________________
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 04-01-2020, 02:27 AM
chriscla chriscla is offline Multiple entries in dropdown lists with building blocks Windows 10 Multiple entries in dropdown lists with building blocks Office 2013
Novice
Multiple entries in dropdown lists with building blocks
 
Join Date: Mar 2020
Posts: 18
chriscla is on a distinguished road
Default

Hi Graham


Thanks a lot. This is what I was looking for.
One small itch: if there is a text with multiple paragraphs (with bullet) the outline at the front is not correct.
The first two paragraphs are the control content, the 3rd en 4rd are the autotext (as the outline should be).


Any solution?


Thanks
Chris
Attached Images
File Type: jpg CC_MSW.JPG (60.3 KB, 46 views)
Reply With Quote
  #4  
Old 04-01-2020, 02:36 AM
gmayor's Avatar
gmayor gmayor is offline Multiple entries in dropdown lists with building blocks Windows 10 Multiple entries in dropdown lists with building blocks Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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

That shouldn't happen if the autotext and the body text of the target document use the same styles. Try inserting the Roundhouse autotext entry after the content control in the example and the inserted text should align with the content control text.
__________________
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
  #5  
Old 04-01-2020, 02:39 AM
chriscla chriscla is offline Multiple entries in dropdown lists with building blocks Windows 10 Multiple entries in dropdown lists with building blocks Office 2013
Novice
Multiple entries in dropdown lists with building blocks
 
Join Date: Mar 2020
Posts: 18
chriscla is on a distinguished road
Default

Hi Graham
forget the previous post. I deleted the autotext I had and made a new one. Problem solved.
But I have another question: if I need this somewhere else in my document with a different list box, won't there be a conflict in the VBA if I make a second Private Sub Document_ContentControlOnExit or do I have to integrate my second listbox in the existing VBA?


regards
Chris
Reply With Quote
  #6  
Old 04-01-2020, 04:19 AM
gmayor's Avatar
gmayor gmayor is offline Multiple entries in dropdown lists with building blocks Windows 10 Multiple entries in dropdown lists with building blocks Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 need to combine the code. You can use Select Case to process as many controls as you wish by addressing them by their title property e.g.


Code:
Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
Dim i As Long
Dim oCC As ContentControl
    With ContentControl
        Select Case .Title
            Case Is = "Client"
                If .ShowingPlaceholderText = True Then
                    Set oCC = ActiveDocument.SelectContentControlsByTitle("ClientDetails").Item(1)
                    oCC.LockContentControl = True
                    oCC.Range.Text = ""
                Else
                    For i = 1 To .DropdownListEntries.Count
                        If .DropdownListEntries(i).Text = .Range.Text Then
                            Select Case .DropdownListEntries(i).Text
                                Case "Roundhouse Nurseries"
                                    AutoTextToCC "ClientDetails", ActiveDocument.AttachedTemplate, "Roundhouse"
                                Case "Smiths Wholesales"
                                    AutoTextToCC "ClientDetails", ActiveDocument.AttachedTemplate, "Smith"
                            End Select
                            Exit For
                        End If
                    Next
                End If
            Case Is = "Another listbox"
                If .ShowingPlaceholderText = True Then
                    Set oCC = ActiveDocument.SelectContentControlsByTitle("CC to be processed").Item(1)
                    oCC.LockContentControl = True
                    oCC.Range.Text = ""
                Else
                    For i = 1 To .DropdownListEntries.Count
                        If .DropdownListEntries(i).Text = .Range.Text Then
                            Select Case .DropdownListEntries(i).Text
                                Case "List Item 1"
                                    AutoTextToCC "CC to be processed", ActiveDocument.AttachedTemplate, "Autotext Name 1"
                                Case "List Item 2"
                                    AutoTextToCC "CC to be processed", ActiveDocument.AttachedTemplate, "Autotext Name 2"
                            End Select
                            Exit For
                        End If
                    Next
                End If
        End Select
    End With
End Sub
__________________
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
  #7  
Old 04-01-2020, 10:25 AM
chriscla chriscla is offline Multiple entries in dropdown lists with building blocks Windows 10 Multiple entries in dropdown lists with building blocks Office 2013
Novice
Multiple entries in dropdown lists with building blocks
 
Join Date: Mar 2020
Posts: 18
chriscla is on a distinguished road
Default

Thanks Graham, I will give that a try.
Reply With Quote
  #8  
Old 04-02-2020, 09:30 PM
chriscla chriscla is offline Multiple entries in dropdown lists with building blocks Windows 10 Multiple entries in dropdown lists with building blocks Office 2013
Novice
Multiple entries in dropdown lists with building blocks
 
Join Date: Mar 2020
Posts: 18
chriscla is on a distinguished road
Default

Hi Graham
I must be doing something wrong because I can't get it to work.
I've attached your first dotm file, but changed the VBA according to your last post.
The first list box works fine, the second doesn't. Could you please check what is wrong with it?
My colleagues like the idea very much and even would like to go one step further:
'List box 1' has two options: 'list item 1' and 'list item 2'. When you choose 'list item 1' there is another listbox 'list box 2' with two options: 'box2_item1' and 'box2_item2'. When you choose 'box_item1' a rich text content control is filled with autotext1, when you choose 'box_item2' that rich text content control is filled with autotext2 (is like what we had after your last post).
Is something like this even possible?

Chris
Reply With Quote
  #9  
Old 04-02-2020, 10:39 PM
gmayor's Avatar
gmayor gmayor is offline Multiple entries in dropdown lists with building blocks Windows 10 Multiple entries in dropdown lists with building blocks Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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

It was no use posting my template which worked if you wanted me to check yours.
The code I posted works, if you match the content control names, the values in the list and the autotext names - see attached
__________________
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
  #10  
Old 04-03-2020, 12:44 AM
chriscla chriscla is offline Multiple entries in dropdown lists with building blocks Windows 10 Multiple entries in dropdown lists with building blocks Office 2013
Novice
Multiple entries in dropdown lists with building blocks
 
Join Date: Mar 2020
Posts: 18
chriscla is on a distinguished road
Default

Sorry, my mistake . I did attach the wrong file. Everything is working great now, so thanks. Could you give me a hint on how to get the cascade of my previous post? BTW, this should be a 3rd listbox situation in my document.
Reply With Quote
  #11  
Old 04-03-2020, 01:50 AM
gmayor's Avatar
gmayor gmayor is offline Multiple entries in dropdown lists with building blocks Windows 10 Multiple entries in dropdown lists with building blocks Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 add more case statements to work with the as many list boxes as you want, however if you want list boxes that are only present and dependent on an earlier selection then it gets altogether more complicated, especially when we only have a vague outline of what it is that you are trying to achieve.

Personally if that is the aim I would go instead form a userform with cascading list boxes and write only the final values to the document based on what is selected - see Populate Userform Listbox or Combobox
__________________
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
  #12  
Old 04-03-2020, 02:26 AM
chriscla chriscla is offline Multiple entries in dropdown lists with building blocks Windows 10 Multiple entries in dropdown lists with building blocks Office 2013
Novice
Multiple entries in dropdown lists with building blocks
 
Join Date: Mar 2020
Posts: 18
chriscla is on a distinguished road
Default

Hi Graham, this is what I would like to achieve:
I have a list box 'Products' with two products: ProductA en ProductB. Each product can be used under two conditions: ConditionA and Condition B. Therefore I have a second list box 'Conditions'.
For each condition there is an explanation that should come in a rich text CC, so I have therefore ProdA_Cond1 autotext, ProdB_Cond2 autotext, ...



E.g. I choose ProductB in list box 'Products'. A new list box 'Conditions' becomes available. In list box 'Conditions' I choose Condition 1 and then in a rich text CC ProdB_Cond1 should appear.


And this is all in the same document as the one with which you helped me already a great deal
Reply With Quote
  #13  
Old 04-03-2020, 11:02 PM
chriscla chriscla is offline Multiple entries in dropdown lists with building blocks Windows 10 Multiple entries in dropdown lists with building blocks Office 2013
Novice
Multiple entries in dropdown lists with building blocks
 
Join Date: Mar 2020
Posts: 18
chriscla is on a distinguished road
Default

While I'm still struggling with my previous question , I encountered a problem with something that works fine (thanks to Graham) on two locations in my document, but fails in a third location.
I've attached a test file, where 'Kies een item' en 'Niet in de zomer' are doing what they are supposed to do: give text in a rich text CC, and where 'Enkel in de winter' refuses to give the required text.
I've tried several other control names, ... but no luck.
(in the code of the doc6.dotm file are also the two other locations that work just fine)



Anyone?
Thx
Attached Files
File Type: dotm Doc6.dotm (31.4 KB, 14 views)
Reply With Quote
  #14  
Old 04-04-2020, 05:24 AM
gmayor's Avatar
gmayor gmayor is offline Multiple entries in dropdown lists with building blocks Windows 10 Multiple entries in dropdown lists with building blocks Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
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 regard to your template, your code is


Code:
Case Is = "Zomer/winter"
                If .ShowingPlaceholderText = True Then
                    Set oCC = ActiveDocument.SelectContentControlsByTitle("WinterTekst").Item(1)
                    oCC.LockContentControl = True
                    oCC.Range.Text = ""
                Else
                    For i = 1 To .DropdownListEntries.Count
                        If .DropdownListEntries(i).Text = .Range.Text Then
                            Select Case .DropdownListEntries(i).Text
                                Case "Kies een item."
                                    AutoTextToCC "WinterTekst", ActiveDocument.AttachedTemplate, "TipKeuze"
                                Case "Enkel in de winter"
                                    AutoTextToCC "WinterTekst", ActiveDocument.AttachedTemplate, "PrimerAnhydriet"
                                Case "Niet in de zomer"
                                    AutoTextToCC "WinterTekst", ActiveDocument.AttachedTemplate, "TipZomer"
                            End Select
                            Exit For
                        End If
                    Next
                 End If

There is no "PrimerAnhydriet" building block, so that one is never going to work, and Case "Kies een item." is superfluous as that is the placeholder text and always produces nothing because of the other half of the IF statement.
__________________
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
  #15  
Old 04-04-2020, 09:34 AM
chriscla chriscla is offline Multiple entries in dropdown lists with building blocks Windows 10 Multiple entries in dropdown lists with building blocks Office 2013
Novice
Multiple entries in dropdown lists with building blocks
 
Join Date: Mar 2020
Posts: 18
chriscla is on a distinguished road
Default

Stupid me . Of course it works when you do it right.
Still struggling with the multiple dependent list boxes. Probably it is simple, but I don't see it.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple entries in dropdown lists with building blocks Multiple entries in dropdown lists paul_pearson Word VBA 151 10-18-2023 04:23 PM
Muliple entries in Multiple dropdown lists Haygordon Word VBA 7 04-04-2019 06:28 AM
VBA Word - Building Block (AutoText) - Array - Replace Text with Specific Building Blocks jc491 Word VBA 7 01-03-2016 10:34 PM
Multiple entries in dropdown lists with building blocks Open Quickpart file normalemail.dotm - edit multiple building blocks rollno Word 7 02-24-2014 04:29 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 01:55 PM.


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