Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如何获取列表框中选定的项目名称?_Vba_Powerpoint_Listboxitem - Fatal编程技术网

Vba 如何获取列表框中选定的项目名称?

Vba 如何获取列表框中选定的项目名称?,vba,powerpoint,listboxitem,Vba,Powerpoint,Listboxitem,如何在列表框中获取项目名称 我有以下代码: Dim x2 As Long Dim OriginalCount2 As Long 'Store original ListBox count OriginalCount2 = ListBox1.ListCount 'Temporarily hide ListBox (runs faster) ListBox1.Visible = False 'Delete selected line items For x2 = OriginalCoun

如何在列表框中获取项目名称

我有以下代码:

Dim x2 As Long
Dim OriginalCount2 As Long
'Store original ListBox count
  OriginalCount2 = ListBox1.ListCount
'Temporarily hide ListBox (runs faster)
  ListBox1.Visible = False
'Delete selected line items
  For x2 = OriginalCount2 - 1 To 0 Step -1
    If ListBox1.Selected(x2) = True Then MsgBox x2
  Next x2
'Unhide ListBox
  ListBox1.Visible = True

但它只获取项目索引。

有助于了解触发代码的事件或操作是什么,但这应该让您从正确的方向开始:

Private Sub ListBox1_Click()
    Dim LBItem As Long
    For LBItem = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(LBItem) = True Then
            MsgBox (ListBox1.List(LBItem))
        End If
    Next
End Sub

嗯..如何在文本框上显示?要在文本框上显示,只需将:MsgBox(ListBox1.List(LBItem))更改为Textbox1=(ListBox1.List(LBItem)),这将有助于进一步了解代码的来源和去向。