从下拉框中返回所选文字 [英] Return the selected text from a dropdown box

查看:134
本文介绍了从下拉框中返回所选文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Excel表单中选择的下拉框返回文本。我尝试了许多事情,最接近的是返回索引号。另外看一下:

I am trying to return the text from a dropdown box that is selected on an Excel form. I have tried many things and the closest I have gotten is returning the index number. Also had a look at:

链接:从下拉框中返回文本而不是索引号

我没有在该页面上找到一个工作解决方案。我尝试过的东西,如:

I haven't found a working solution on that page. I have tried things such as:

ActiveSheet.DropDowns("DropDown1").Value
ActiveSheet.DropDowns("DropDown1").Text
ActiveSheet.DropDowns("DropDown1").SelectedValue
ActiveSheet.Shapes("DropDown1").Value

等。

推荐答案

这将从DropDown返回当前选择



This will return the current selection from the DropDown

Sub TestDropdown()
    Dim ws As Worksheet
    Dim dd As DropDown

    Set ws = ActiveSheet
    Set dd = ws.Shapes("DropDown1").OLEFormat.Object

    MsgBox dd.List(dd.ListIndex)
End Sub

BTW,分配给声明为的变量Dim dd As DropDown 将在 dd上给你智能感知

BTW, assigning to a variable declared as Dim dd As DropDown will give you intellisense on dd

这篇关于从下拉框中返回所选文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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