0

I have two drop down fields naming:

  1. App Language:_____
  2. App Country: _____

App country is dependent on app language field. Every time user select a language app from drop down list (a Macro is run and) the Country field will show relevant countries only.

So problem is "drop-down form field" naming app language which should contain more than 84 item but every time I run following macro it show error "you can not add more than 25 items in the list":

Sub Alang()
With ActiveDocument.FormFields("alang").DropDown.ListEntries
.Clear
.Add "Afrikaans"
.Add "Albanian"
.Add "Arabic"
.Add "Assamese"
.Add "Belarusian"
.Add "Bengali"
.Add "Bosnian"
.Add "Bulgarian"
.Add "Catalan"
.Add "Cebuano"
.Add "Chinese - Simplified"
.Add "Chinese - Traditional"
.Add "Haitian Creole"
.Add "Croatian"
.Add "Czech"
.Add "Dagbani"
.Add "Danish"
.Add "Dholuo"
.Add "Dutch"
.Add "English"
.Add "Estonian"
.Add "Ewe"
.Add "Finnish"
.Add "French"
.Add "Gaelic - Irish"
.Add "Georgian"
.Add "German"
.Add "Greek"
.Add "Gujarati"
.Add "Hebrew"
.Add "Hiligaynon"
.Add "Hindi"
.Add "Hungarian"
.Add "Icelandic"
.Add "Iloko/Ilocano"
.Add "Indonesian"
.Add "Italian"
.Add "Itesot"
.Add "Japadhola"
.Add "Japanese"
.Add "Kannada"
.Add "Korean"
.Add "Latvian"
.Add "Lithuanian"
.Add "Luganda"
.Add "Macedonian"
.Add "Malay"
.Add "Malayalam"
.Add "Marathi"
.Add "Norwegian"
.Add "Odia/Oriya"
.Add "Pedi"
.Add "Polish"
.Add "Portuguese (Brazil)"
.Add "Portuguese (Portugal)"
.Add "Punjabi"
.Add "Romanian"
.Add "Russian"
.Add "Serbian - Cyrillic"
.Add "Serbian - Latin"
.Add "Sesotho"
.Add "Setswana"
.Add "Sinhalese"
.Add "Slovak"
.Add "Slovenian"
.Add "Spanish"
.Add "Spanish (Universal)"
.Add "Swahili"
.Add "Swedish"
.Add "Tagalog"
.Add "Tamil"
.Add "Telugu"
.Add "Thai"
.Add "Tsonga"
.Add "Turkish"
.Add "Twi"
.Add "Ukrainian"
.Add "Urdu"
.Add "Uyghur"
.Add "Venda"
.Add "Vietnamese"
.Add "Welsh"
.Add "Xhosa"
.Add "Zulu"
End With

End Sub

Please! suggest this method is correct or I need to switch to another or there is another method of adding more than 25 items in the drop down list?

VBAbyMBA
  • 806
  • 2
  • 12
  • 30
  • 1
    A simple Google search: https://support.microsoft.com/en-us/topic/how-to-create-a-word-combo-box-that-has-more-than-25-items-from-a-microsoft-access-database-13f99a97-0e67-f931-3377-ce1fa492ff75 – StureS Mar 09 '21 at 06:54

2 Answers2

2

Unless you're trying to support really old versions of Word, I second Macropod's content control suggestion. Word for Mac 2011 was the last version that didn't support them. Here's your code in a content control version:

Sub Alang()
    Dim oCC As ContentControl
        
    For Each oCC In ActiveDocument.ContentControls
        If oCC.Title = "alang" Then
            With oCC.DropdownListEntries
                .Clear
                .Add "Afrikaans"
                'Other languages here
            End With
        End If
    Next oCC
End Sub
John Korchok
  • 4,723
  • 2
  • 11
  • 20
  • Great! But I need to use this list to run a macro whenever a language is selected. as I mention earlier that my second list (app Country) is dependent on language I select. Which is only possible with `legacy tools` ? – VBAbyMBA Mar 10 '21 at 06:51
  • We've already established that a legacy dropdown can't do what you want. It has a fixed maximum size that can't be expanded, so you need to start working on workarounds: https://gregmaxey.com/word_tip_pages/content_control_custom_events.html – John Korchok Mar 10 '21 at 16:39
1

You cannot add more than 25 items to a formfield dropdown in MS Word. That is a design limitation.

Instead of using a formfield dropdown, you should consider using a content control dropdown. Content control dropdowns can have hundreds, if not thousands, of entries (though how you'd manage choosing an item from such a monster doesn't bear thinking about). For example:

Sub Demo()
Application.ScreenUpdating = False
Dim i As Long
Const StrList As String = "|Afrikaans|Albanian|Arabic|Assamese|Belarusian|Bengali|" & _
  "Bosnian|Bulgarian|Catalan|Cebuano|Chinese - Simplified|Chinese - Traditional|" & _
  "Creole - Haitian|Croatian|Czech|Dagbani|Danish|Dholuo|Dutch|English|Estonian|" & _
  "Ewe|Finnish|French|Gaelic - Irish|Gaelic - Welsh|Georgian|German|Greek|Gujarati|" & _
  "Hebrew|Hiligaynon|Hindi|Hungarian|Icelandic|Iloko/Ilocano|Indonesian|" & _
  "Italian|Itesot|Japadhola|Japanese|Kannada|Korean|Latvian|Lithuanian|" & _
  "Luganda|Macedonian|Malay|Malayalam|Marathi|Norwegian|Odia/Oriya|Pedi|" & _
  "Polish|Portuguese (Brazil)|Portuguese (Portugal)|Punjabi|Romanian|Russian|" & _
  "Serbian - Cyrillic|Serbian - Latin|Sesotho|Setswana|Sinhalese|Slovak|" & _
  "Slovenian|Spanish|Spanish (Universal)|Swahili|Swedish|Tagalog|Tamil|Telugu|" & _
  "Thai|Tsonga|Turkish|Twi|Ukrainian|Urdu|Uyghur|Venda|Vietnamese|Welsh|Xhosa|Zulu"
With ActiveDocument.SelectContentControlsByTitle("alang")
  For c = 1 To .Count
    With .Item(c)
      .SetPlaceholderText Text:="Choose a Language"
      With .DropdownListEntries
        .Clear
        For i = 1 To UBound(Split(StrList, "|"))
          .Add Split(StrList, "|")(i)
        Next
      End With
    End With
  Next
End With
Application.ScreenUpdating = True
End Sub

Of course, using a content control dropdown might require an entirely different approach to other aspects of whatever you're doing; for one thing, formfields and content controls should not be used in the same document. They weren't designed to be used that way and trying to do so is a known source of problems.

macropod
  • 12,757
  • 2
  • 9
  • 21
  • nicely done! But I need to use this list to run a macro whenever a language is selected. as I mention earlier that my second list (app Country) is dependent on language I select. Which is only possible with `legacy tools` ? – VBAbyMBA Mar 10 '21 at 06:51
  • In which case use a content control on exit macro to perform whatever actions you require. – macropod Mar 10 '21 at 12:24