从下拉框中返回选定的文本

我想从Excel窗体上select的下拉框中返回文本。 我已经尝试了很多东西,最近得到的是返回索引号。 还看了一下:

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

我还没有find该页面上的工作解决scheme。 我曾尝试过这样的事情:

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

等等

这将从DropDown返回当前的select

 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 

顺便说一句,分配给一个variables声明为Dim dd As DropDown将给你dd intellisense

如果macros由下拉框本身调用,您也可以获取调用者名称。 这样你不必担心重命名下拉框:)

 Sub Dropdown_OnSelect() Dim dd As DropDown Set dd = ActiveSheet.Shapes(Application.Caller).OLEFormat.Object MsgBox dd.List(dd.ListIndex) End Sub 

如果你不能Dim as DropDown我发现这种改变将工作。

 Sub TestDropdown() Dim ws As Worksheet Dim dd As Object Set ws = ActiveSheet Set dd = ws.DropDowns("DropDown1") MsgBox dd.List(dd.ListIndex) End Sub