Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-13-2018, 04:16 AM
deepak_fer deepak_fer is offline Combo Box Content Control: How to update the list throughout the whole document? Windows 10 Combo Box Content Control: How to update the list throughout the whole document? Office 2016
Novice
Combo Box Content Control: How to update the list throughout the whole document?
 
Join Date: Mar 2018
Posts: 5
deepak_fer is on a distinguished road
Default Combo Box Content Control: How to update the list throughout the whole document?

Hello,

I am new to this and I had a specific question. Hope you can help me out here..
I have tried my best to explain but also, I have attached a part of the document in case it helps to better understand my problem.

I have a table of 5 rows and 3 columns. For every row of the 3rd column, I created a drop down list using Combo box content control and then I copied/ pasted this table multiple times in my documents. (About 100 tables now)



Later on, I realized that, some of the items in the drop down list needed to be edited.
The problem is, If i edit it in one box, its only for that box.

Is there a way where all the Combo Box Content Control's can be updated at once?

Thanks
Attached Files
File Type: docx MS Forums.docx (55.0 KB, 15 views)
Reply With Quote
  #2  
Old 03-13-2018, 06:03 AM
gmayor's Avatar
gmayor gmayor is offline Combo Box Content Control: How to update the list throughout the whole document? Windows 10 Combo Box Content Control: How to update the list throughout the whole document? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
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 macro to update them. If you make a list of the entries in a text file - one per line - omitting the prompt text, the following macro will replace all the lists in all the dropdown content controls in a selection with the items in the named text file

Code:
Sub Macro1()
Dim oRng As Range
Dim oCC As ContentControl
Dim lngCC As Long
Dim iLst As Integer
Dim strListItem As String
Const strList As String = "C:\path\ccList.txt"
Dim iFile As Integer: iFile = FreeFile
    Set oRng = Selection.Range
    For lngCC = 1 To oRng.ContentControls.Count
        Set oCC = oRng.ContentControls(lngCC)
        If oCC.Type = wdContentControlComboBox Or _
           oCC.Type = wdContentControlDropdownList Then
            'leave the prompt text and delete the rest
            For iLst = oCC.DropdownListEntries.Count To 2 Step -1
                oCC.DropdownListEntries(iLst).Delete
            Next iLst
        End If
        'add the new list from a text file
        Open strList For Input As #iFile
        Do Until EOF(1)
            Line Input #1, strListItem
            oCC.DropdownListEntries.Add strListItem
        Loop
        Close #iFile
    Next lngCC
lbl_Exit:
    Set oRng = Nothing
    Set oCC = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com

Last edited by gmayor; 03-13-2018 at 09:00 AM.
Reply With Quote
  #3  
Old 03-13-2018, 07:43 AM
Charles Kenyon Charles Kenyon is offline Combo Box Content Control: How to update the list throughout the whole document? Windows 10 Combo Box Content Control: How to update the list throughout the whole document? Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

It is also likely that if it is a mapped control it will automatically update.
I would use Greg Maxey's Content Control Tools to do this.

(I haven't tried it with a combobox, but know of no reason it would not work. I may be simply exposing my ignorance.)
Reply With Quote
  #4  
Old 03-13-2018, 07:52 AM
Charles Kenyon Charles Kenyon is offline Combo Box Content Control: How to update the list throughout the whole document? Windows 10 Combo Box Content Control: How to update the list throughout the whole document? Office 2013
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

I just tried it with a mapped control and it does not work. Sorry for the red herring!

However, if you wanted the same choice selected in each of the controls, it should do that.
Reply With Quote
  #5  
Old 03-15-2018, 01:44 AM
deepak_fer deepak_fer is offline Combo Box Content Control: How to update the list throughout the whole document? Windows 10 Combo Box Content Control: How to update the list throughout the whole document? Office 2016
Novice
Combo Box Content Control: How to update the list throughout the whole document?
 
Join Date: Mar 2018
Posts: 5
deepak_fer is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
You could use a macro to update them. If you make a list of the entries in a text file - one per line - omitting the prompt text, the following macro will replace all the lists in all the dropdown content controls in a selection with the items in the named text file

Code:
Sub Macro1()
Dim oRng As Range
Dim oCC As ContentControl
Dim lngCC As Long
Dim iLst As Integer
Dim strListItem As String
Const strList As String = "C:\path\ccList.txt"
Dim iFile As Integer: iFile = FreeFile
    Set oRng = Selection.Range
    For lngCC = 1 To oRng.ContentControls.Count
        Set oCC = oRng.ContentControls(lngCC)
        If oCC.Type = wdContentControlComboBox Or _
           oCC.Type = wdContentControlDropdownList Then
            'leave the prompt text and delete the rest
            For iLst = oCC.DropdownListEntries.Count To 2 Step -1
                oCC.DropdownListEntries(iLst).Delete
            Next iLst
        End If
        'add the new list from a text file
        Open strList For Input As #iFile
        Do Until EOF(1)
            Line Input #1, strListItem
            oCC.DropdownListEntries.Add strListItem
        Loop
        Close #iFile
    Next lngCC
lbl_Exit:
    Set oRng = Nothing
    Set oCC = Nothing
    Exit Sub
End Sub
Hi gmayor,

Thank you for the code.

Can I do this for multiple combo boxes?
I mean, all 5 boxes in the table will have different content.

All the 5 boxes in the table are named/ titled differently. If copy/ paste this table multiple times, then I have one particular named box in each of those table.
How can I edit this code such that it updates that particular box in all the tables?

I hope you understand what i am trying to say.. Tried my best to explain..
Reply With Quote
  #6  
Old 03-15-2018, 02:52 AM
gmayor's Avatar
gmayor gmayor is offline Combo Box Content Control: How to update the list throughout the whole document? Windows 10 Combo Box Content Control: How to update the list throughout the whole document? Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,105
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

The short answer is no, however if the content controls are titled and/or tagged you can loop through the content controls and process only those that have a particular title/tag.

You can title/tag the controls if necessary with http://www.gmayor.com/ExtractDataFromForms.htm

If you title the similar fields with a common name e.g. Table1_Name Table2_Name then you can use the following to modify all the fields named like *Table e.g.

Code:
Option Explicit

Sub Macro2()
Dim oRng As Range
Dim oCC As ContentControl
Dim lngCC As Long
Dim iLst As Integer
Dim strListItem As String
Dim strTitle As String
Const strList As String = "C:\path\ccList.txt"
Dim iFile As Integer: iFile = FreeFile
    Set oRng = ActiveDocument.Range
    For lngCC = 1 To oRng.ContentControls.Count
        Set oCC = oRng.ContentControls(lngCC)
        strTitle = oCC.Title
        Debug.Print strTitle
        If strTitle Like "*Name" Then
            If oCC.Type = wdContentControlComboBox Or _
               oCC.Type = wdContentControlDropdownList Then
                'leave the prompt text and delete the rest
                For iLst = oCC.DropdownListEntries.Count To 2 Step -1
                    oCC.DropdownListEntries(iLst).Delete
                Next iLst
            End If
            'add the new list from a text file
            Open strList For Input As #iFile
            Do Until EOF(1)
                Line Input #1, strListItem
                oCC.DropdownListEntries.Add strListItem
            Loop
            Close #iFile
        End If
    Next lngCC
lbl_Exit:
    Set oRng = Nothing
    Set oCC = Nothing
    Exit Sub
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 03-15-2018, 04:57 AM
deepak_fer deepak_fer is offline Combo Box Content Control: How to update the list throughout the whole document? Windows 10 Combo Box Content Control: How to update the list throughout the whole document? Office 2016
Novice
Combo Box Content Control: How to update the list throughout the whole document?
 
Join Date: Mar 2018
Posts: 5
deepak_fer is on a distinguished road
Default

Thank you Graham

Okay.. But that also means I should have 5 different lists.
And then, Combo box with "Title A" should be updated from List A
Combo box with "Title B" should be updated from List B.. and so on ..

This is interesting..

Is it possible to do that from 1 macro itself? or I should make 5 different macro's with the code you gave above.? So i can put 5 different lists and 5 different tags in 5 different macro's
Reply With Quote
  #8  
Old 03-17-2018, 10:50 PM
deepak_fer deepak_fer is offline Combo Box Content Control: How to update the list throughout the whole document? Windows 10 Combo Box Content Control: How to update the list throughout the whole document? Office 2016
Novice
Combo Box Content Control: How to update the list throughout the whole document?
 
Join Date: Mar 2018
Posts: 5
deepak_fer is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
You could use a macro to update them. If you make a list of the entries in a text file - one per line - omitting the prompt text, the following macro will replace all the lists in all the dropdown content controls in a selection with the items in the named text file

Code:
Sub Macro1()
Dim oRng As Range
Dim oCC As ContentControl
Dim lngCC As Long
Dim iLst As Integer
Dim strListItem As String
Const strList As String = "C:\path\ccList.txt"
Dim iFile As Integer: iFile = FreeFile
    Set oRng = Selection.Range
    For lngCC = 1 To oRng.ContentControls.Count
        Set oCC = oRng.ContentControls(lngCC)
        If oCC.Type = wdContentControlComboBox Or _
           oCC.Type = wdContentControlDropdownList Then
            'leave the prompt text and delete the rest
            For iLst = oCC.DropdownListEntries.Count To 2 Step -1
                oCC.DropdownListEntries(iLst).Delete
            Next iLst
        End If
        'add the new list from a text file
        Open strList For Input As #iFile
        Do Until EOF(1)
            Line Input #1, strListItem
            oCC.DropdownListEntries.Add strListItem
        Loop
        Close #iFile
    Next lngCC
lbl_Exit:
    Set oRng = Nothing
    Set oCC = Nothing
    Exit Sub
End Sub
Hi Graham,

Can this list be embedded into the document or in the macro itself?

The reason is, I want to make this document future proof..
So when i send this to the client, I also need to send the notepad list.

So i was thinking if its possible to embed that list, so that there is no need to send additional stuff that may/ may not confuse them.

Thanks for your patience and help.
Reply With Quote
  #9  
Old 03-18-2018, 03:02 AM
Guessed's Avatar
Guessed Guessed is offline Combo Box Content Control: How to update the list throughout the whole document? Windows 10 Combo Box Content Control: How to update the list throughout the whole document? Office 2013
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The source lists can be coded into the vba but then the client is going to be confused even more if they need to edit the vba. You could also embed the lists in a custom xml file but there is no real benefit in terms of making it easy for the client to update the list.

IMO the slickest way would be to set up the first instance of each CB as the 'master' and allow the user to manually update that instance and then have the macro copy that list to the other related instances.

So use the Title property of each CC to link the series. And use the Tag property to define the CC which contains the master list for that series. Then use the following macro to copy the list from each 'Master' to the other CCs which share its Title property.
Code:
Sub UpdateCCList()
  Dim aCCMaster As ContentControl, aCC As ContentControl, i As Integer, sTitle As String
  For Each aCCMaster In ActiveDocument.SelectContentControlsByTag("Master")
    sTitle = aCCMaster.Title
    For Each aCC In ActiveDocument.SelectContentControlsByTitle(sTitle)
      If aCC.Tag <> "Master" Then
        aCC.DropdownListEntries.Clear
        For i = 1 To aCCMaster.DropdownListEntries.Count
          aCC.DropdownListEntries.Add aCCMaster.DropdownListEntries(i).Text
        Next i
      End If
    Next aCC
  Next aCCMaster
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #10  
Old 03-18-2018, 04:10 AM
deepak_fer deepak_fer is offline Combo Box Content Control: How to update the list throughout the whole document? Windows 10 Combo Box Content Control: How to update the list throughout the whole document? Office 2016
Novice
Combo Box Content Control: How to update the list throughout the whole document?
 
Join Date: Mar 2018
Posts: 5
deepak_fer is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
The source lists can be coded into the vba but then the client is going to be confused even more if they need to edit the vba. You could also embed the lists in a custom xml file but there is no real benefit in terms of making it easy for the client to update the list.

IMO the slickest way would be to set up the first instance of each CB as the 'master' and allow the user to manually update that instance and then have the macro copy that list to the other related instances.

So use the Title property of each CC to link the series. And use the Tag property to define the CC which contains the master list for that series. Then use the following macro to copy the list from each 'Master' to the other CCs which share its Title property.
Code:
Sub UpdateCCList()
  Dim aCCMaster As ContentControl, aCC As ContentControl, i As Integer, sTitle As String
  For Each aCCMaster In ActiveDocument.SelectContentControlsByTag("Master")
    sTitle = aCCMaster.Title
    For Each aCC In ActiveDocument.SelectContentControlsByTitle(sTitle)
      If aCC.Tag <> "Master" Then
        aCC.DropdownListEntries.Clear
        For i = 1 To aCCMaster.DropdownListEntries.Count
          aCC.DropdownListEntries.Add aCCMaster.DropdownListEntries(i).Text
        Next i
      End If
    Next aCC
  Next aCCMaster
End Sub
Hi Andrew,

Thank you so much.
It works like a charm and I think it will be easier for the client to understand and as it is embedded in the document, I love it!

Really appreciate it!

Cheers
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Combo Box Content Control: How to update the list throughout the whole document? How to get a Drop Down List Content Control box to fill in other areas snips1982 Word 2 03-22-2017 03:37 AM
Combo Box Content Control: How to update the list throughout the whole document? Multi-column combo box content control? sugarjay Word 1 03-21-2017 07:20 PM
Combo Box Content Control Calculate on selection help ciresuark Word 0 03-06-2015 01:49 PM
Word 2010 Content Control help - Combo Boxes vs Drop Down List proghy Word 1 09-16-2014 02:01 PM
Download Content Control List cjacob28 Word 0 06-26-2011 11:23 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:45 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