用户窗体VBA的列表框项目上的双击事件 [英] Double Click Event on the items of the ListBox of a Userform VBA

查看:226
本文介绍了用户窗体VBA的列表框项目上的双击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用vba在excel上做一个小的另存为"界面,以便可以将我已放入工作表中的某些信息保存在另一工作表中.我差不多完成了,它看起来像这样:单击此处查看我的另存为"界面

I am trying to do a small "save as" interface on excel using vba, so that I can save some of the information that i have putted in my sheet in another sheet. I am almost done with it and it looks like this: click here to see my Save As interface

我的问题是我想双击列表中的一个元素(例如SoCs2)来创建一个事件.双击时,我希望字符串"SoCs2"出现在下面的文本框中.

My problem is that I want to put an event on double clicking on one of the elements of my list, let's say SoCs2. On double click, I want the string "SoCs2" to appear in the textbox below.

我尝试过类似的事情:

Private Sub Listbox1_BeforeDoubleClick(ByVal Cancel As MSForms.ReturnBoolean)

With Me.ListBox1
     For i = 0 To .ListCount - 1
       If .Selected(i) Then
         Me.TextBox1.Value = .List(i, 0)
         Exit For
       End If
     Next
End With

End Sub

我的ListBox称为ListBox1,而我的TextBox称为TextBox1.不幸的是,此代码无法正常工作:当我双击ListBox的一项时,它绝对不会执行任何操作.有人可以帮我解决这个问题吗?

My ListBox is called ListBox1 and my TextBox is called TextBox1. Unfortunately, this code doesn't work: when I double click on one of the items of my ListBox, it does absolutely nothing. Can somebody help me with this issue ?

推荐答案

要查找的事件处理程序的名称为Listbox1_DblClick.试试这个:

The name of the Event Handler you are looking for is Listbox1_DblClick. Try this:

Private Sub Listbox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  With Me.ListBox1
    For i = 0 To .ListCount - 1
      If .Selected(i) Then
        Me.TextBox1.Value = .List(i, 0)
        Exit For
      End If
    Next
  End With

End Sub

这篇关于用户窗体VBA的列表框项目上的双击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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