0

我有两个下拉字段命名:

  1. 应用语言:_____
  2. 应用国家:_____

App country取决于app language场。每次用户从下拉列表中选择一个语言应用程序(aMacro运行并且)“国家/地区”字段将仅显示相关国家/地区。

所以问题是“下拉表单字段”命名app language应该包含超过 84 个项目但每次我运行以下宏时都会显示错误“你不能在列表中添加超过 25 个项目”:

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

请!建议这种方法是正确的还是我需要切换到另一个或者有另一种方法可以在下拉列表中添加超过 25 个项目?

4

2 回答 2

2

除非您尝试支持真正旧版本的 Word,否则我将支持 Macropod 的内容控制建议。Word for Mac 2011 是最后一个不支持它们的版本。这是内容控制版本中的代码:

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
于 2021-03-09T19:08:13.533 回答
1

不能向 MS Word 中的表单域下拉列表添加超过 25 个项目。这是一个设计限制。

您应该考虑使用内容控件下拉菜单,而不是使用表单字段下拉菜单。内容控制下拉菜单可以有数百个,如果不是数千个条目(尽管你如何管理从这样一个怪物中选择一个项目不值得考虑)。例如:

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

当然,使用内容控件下拉菜单可能需要完全不同的方法来处理您正在做的任何事情的其他方面;一方面,表单域和内容控件不应该在同一个文档中使用。它们并非设计为以这种方式使用,并且试图这样做是一个已知的问题来源。

于 2021-03-09T12:01:58.473 回答