我正在尝试获取该名称Listbox
我刚刚选择的(“ListBox1”)。
Caveat: ListBox1
位于Multipage1
(在第一个选项卡上)。
Private Sub ListBox1_Click()
Dim m As String
m = Me.ActiveControl.Name
MsgBox (m)
End Sub
既然我选择了ListBox1
,我期望消息框值为ListBox1.
相反,我收到多页1.
我应该采取什么不同的做法?
将多页、页面和框架视为子表单会有所帮助。如果子窗体控件处于活动状态,则父窗体将返回子窗体作为 ActiveControl。
这是深入了解实际 ActiveControl 的正确方法。
Function ActiveControlName(Object As Object) As String
Dim Obj As Object
On Error Resume Next
Set Obj = Object.ActiveControl
If Err.Number = 0 Then
ActiveControlName = ActiveControlName(Object.ActiveControl)
Else
Set Obj = Object.SelectedItem
If Err.Number = 0 Then
ActiveControlName = ActiveControlName(Object.SelectedItem)
Else
ActiveControlName = Object.Name
End If
End If
On Error GoTo 0
End Function
Demo
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)