【问题标题】:Need a VBA code for autotext from dropdown menu需要下拉菜单中自动文本的 VBA 代码
【发布时间】:2023-01-18 04:15:17
【问题描述】:

我正在编写代码以从下拉列表中选择特定的自动文本。自从 1970 年代后期旧的 Basic A 以来,我就没有写过代码……我已经忘记了大部分。

下拉列表称为 HVAC 要插入的文本位于名为“Split Systems”的自动文本文件中或与下拉项关联的任何文本中
错误信息是“5941 请求的集合成员不存在”

我试过在 if 语句行中使用 1、2、3 或 4 的值而不是“Split...”,它也不起作用

问题在哪里或我应该如何编码。

我的代码如下:

    Sub one()

    If ActiveDocument.Formfields(hvac).DropDown.Value = "Split Systems" Then GoTo 10 Else GoTo 20

    10
    ActiveDocument.Content.Select  
    Selection.Collapse Direction:=wdCollapseEnd
    ActiveDocument.AttachedTemplate.AutoTextEntries("Split Systems").Insert _
    Where:=Selection.Range, RichText:=True
    GoTo 100
    20

    If ActiveDocument.Formfields(hvac).DropDown.Value = "Packaged Systems" Then GoTo 25 Else GoTo 30
 
    25
    ActiveDocument.Content.Select
    Selection.Collapse Direction:=wdCollapseEnd
    ActiveDocument.AttachedTemplate.AutoTextEntries("Packaged System").Insert _
    Where:=Selection.Range, RichText:=True
    GOto 100
    30

    If ActiveDocument.Formfields(hvac).DropDown.Value = Central Heating System" Then GoTo 35 Else GoTo 40

    35
    ActiveDocument.Content.Select
    Selection.Collapse Direction:=wdCollapseEnd
    ActiveDocument.AttachedTemplate.AutoTextEntries("Central Heating System").Insert _
    Where:=Selection.Range, RichText:=True
    GoTo 100
    40
    If ActiveDocument.Formfields(hvac).DropDown.Value = "PTACs" Then GoTo 45
    45
    ActiveDocument.Content.Select
    Selection.Collapse Direction:=wdCollapseEnd
    ActiveDocument.AttachedTemplate.AutoTextEntries("Central Heating System").Insert _
    Where:=Selection.Range, RichText:=True

    100

    End Sub

尝试了我所知道的一切

【问题讨论】:

    标签: vba ms-word


    【解决方案1】:

    Word 现在有Building Block Gallery 内容控件无需向下拉菜单添加代码。选择开发商选项卡,然后选择Building Block Gallery 内容控制在控制组中。使用特性控件组中的按钮以将控件指向自动文本.唯一的重大缺点是此控件目前在 Word for Mac 中不起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多