英文:
Cell content upload when choosing dropdown menu option Word/VBA
问题
我被要求提供以下内容:
一个包含表格的Word文档,在该表格中,当在单元格内的下拉菜单中选择一个选项时,另一个单元格会更新其内容。
我已经设置了下拉菜单这里是下拉菜单内容控件属性,具有名称和值相等的属性。
在单元格中,我有一个纯文本内容控件这里没有太多要添加的内容。
当我输入以下代码时
Sub UpdateContent()
Dim dropdown As ContentControl
Dim cell As ContentControl
Set dropdown = ActiveDocument.SelectContentControlsByTitle("KörperTypen").Item(1)
Set cell = ActiveDocument.SelectContentControlsByTitle("Klassifizierungen").Item(1)
Select Case dropdown.DropdownListEntries(dropdown.Range.Text).Value
Case "T1001"
cell.Range.Text = "14C33242"
Case "T2001"
cell.Range.Text = "14C33342"
Case "T3001"
cell.Range.Text = "14C43342"
Case "T4001"
cell.Range.Text = "14C33342"
Case "T5001"
cell.Range.Text = "12C33342"
Case "T6001"
cell.Range.Text = "14C33342"
Case "T7001"
cell.Range.Text = "14C33342"
End Select
End Sub
我收到一个错误13类型不匹配。
单元格的名称、纯文本标题和下拉菜单都是正确的。
我尝试将值更改为数字并使用编号系统重试,但无论我做什么,都会得到相同的错误。
如果我尝试查看dropdown.DropdownListEntries(dropdown.Range.Text).Value的结果,它会给我正确的答案(例如"T1001"),但仍然不会运行...
我进行了故障排除并多次进行了仔细检查,我认为这是一个非常简单的任务,我只是太无知,无法自己解决。
我期望在选择下拉菜单中的选项时,单元格会上传纯文本的内容。
我做错了什么?
英文:
So i got requested for:
a word file with a table in it where when picking an option in the drop down menu within a cell, another cell updates it's content.
i have the Drop down set uphere the drop down content control properties with names and values equalized
I have a plain text content control in the cell not much to be added here
when i enter the code
Sub UpdateContent()
Dim dropdown As ContentControl
Dim cell As ContentControl
Set dropdown = ActiveDocument.SelectContentControlsByTitle("KörperTypen").Item(1)
Set cell = ActiveDocument.SelectContentControlsByTitle("Klassifizierungen").Item(1)
Select Case dropdown.DropdownListEntries(dropdown.Range.Text).Value
Case "T1001"
cell.Range.Text = "14C33242"
Case "T2001"
cell.Range.Text = "14C33342"
Case "T3001"
cell.Range.Text = "14C43342"
Case "T4001"
cell.Range.Text = "14C33342"
Case "T5001"
cell.Range.Text = "12C33342"
Case "T6001"
cell.Range.Text = "14C33342"
Case "T7001"
cell.Range.Text = "14C33342"
End Select
End Sub
I get an error 13 type mismatch
the name of the cell, the plain text title, and the dropdown are correct.
i try to chang the values to number and retried with a numbering system, it gives me the same error, regardless of what i do.
If i try to look at the result of the dropdown.DropdownListEntries(dropdown.Range.Text).Value, it gives me the correct answer (ex "T1001"), still it does not run...
I trouble shooted and double checked multiples times, I believe it to be an extremely simple task, i'm just too ignorant to work it out myself.
I expect the cell to upload the contant of the plain text when picking the option in the drop down menú
What am i doing wrong?
答案1
得分: 2
评估组合框的值时,“DropdownListEntries”不相关。您只需要测试内容控件范围的文本,如下所示。
Sub UpdateContent()
Dim dropdown As ContentControl
Dim cell As ContentControl
Set dropdown = ActiveDocument.SelectContentControlsByTitle("KörperTypen").Item(1)
Set cell = ActiveDocument.SelectContentControlsByTitle("Klassifizierungen").Item(1)
Select Case dropdown.Range.Text
Case "T1001"
cell.Range.Text = "14C33242"
Case "T2001"
cell.Range.Text = "14C33342"
Case "T3001"
cell.Range.Text = "14C43342"
Case "T4001"
cell.Range.Text = "14C33342"
Case "T5001"
cell.Range.Text = "12C33342"
Case "T6001"
cell.Range.Text = "14C33342"
Case "T7001"
cell.Range.Text = "14C33342"
End Select
End Sub
英文:
When evaluating the value of a combo-box the DropdownListEntries
are irrelevant. All you need to test is the text of the content control's range, as below.
Sub UpdateContent()
Dim dropdown As ContentControl
Dim cell As ContentControl
Set dropdown = ActiveDocument.SelectContentControlsByTitle("KörperTypen").Item(1)
Set cell = ActiveDocument.SelectContentControlsByTitle("Klassifizierungen").Item(1)
Select Case dropdown.Range.Text
Case "T1001"
cell.Range.Text = "14C33242"
Case "T2001"
cell.Range.Text = "14C33342"
Case "T3001"
cell.Range.Text = "14C43342"
Case "T4001"
cell.Range.Text = "14C33342"
Case "T5001"
cell.Range.Text = "12C33342"
Case "T6001"
cell.Range.Text = "14C33342"
Case "T7001"
cell.Range.Text = "14C33342"
End Select
End Sub
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论