用户从下拉框中选择项目,单击按钮,然后所选项目填充表的最后一行 [英] User selects item from drop down box, clicks button, and the selected item populates the last row of a table

查看:110
本文介绍了用户从下拉框中选择项目,单击按钮,然后所选项目填充表的最后一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用Microsoft的话来说,我有一个3x3的表格,一个按钮和一个下拉列表.

In Microsoft word, I have a 3x3 table, a button, and a drop down list.

当我按下按钮时,我希望第一列的最后一行充满所选的下拉列表项.然后,在其下面的表中添加一行.

When I press the button, I want the last row of the first column to be filled with the selected drop down list item. Then, add a row to the table below it.

目前,我什至无法将值填写到表格中.

Currently, I can't even fill values into the table.

ActiveDocument.Tables(15).Rows.Last.Cells.Value = "Hello"返回错误.我该怎么办?

ActiveDocument.Tables(15).Rows.Last.Cells.Value = "Hello" returns an error. What can I do?

我设法选择了最后一行. ActiveDocument.Tables(15).Rows.Last.Select

I managed to select the last row. ActiveDocument.Tables(15).Rows.Last.Select

现在,我需要从下拉列表中复制当前值.我该怎么办?

Now, I need to copy the current value from the drop down list. How do I do that?

推荐答案

这是一种方法.它将在任何现有文本之后插入文本:

Here is one way. It inserts the text after any existing text:

Option Explicit

Sub PopulateTable()

    With ActiveDocument

        .Tables(1).Rows.Last.Cells(1).Range.InsertAfter .FormFields("DropDown1").Result

    End With

End Sub

如果您知道特定的单元格位置,也可以使用:

If you know the specific cell location you could also use:

.Tables(1).Cell(3, 1).Range.InsertAfter .FormFields("DropDown1").Result

参考文献:

1)表单元-方法字

2) dropdown-object-word

您可以循环查看Activedocument中存在的表单字段,并按以下方式获取其名称:

You can loop so see which form fields are present in the Activedocument and get their names as follows:

Sub GetNames()

Dim myField As FormField

For Each myField In ActiveDocument.FormFields

    Debug.Print myField.Name

Next myField

End Sub

如果双击下拉列表控件,它将打开一个窗口,您可以在其中查看Bookmark名称,即下拉对象的当前名称.

If you double click on the drop down form control it will open a window where you can view the Bookmark name i.e. the current name for the drop down object.

您还可以通过此路由关联宏(这样可以潜在地消除对按钮的需要)

You can also associate a macro via this route (so could remove need for a button potentially)

旧版表单控件:

这篇关于用户从下拉框中选择项目,单击按钮,然后所选项目填充表的最后一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆