Private Sub Command1_Click() Dim objP As Control For Each objP In Me.Controls Debug.Print objP.Name Next
OCX也是记录中的一个 [其他解释] Private Sub UserControl_Initialize() Dim ctrl As Control For Each ctrl In UserControl.Controls Debug.Print ctrl.Name Next End Sub
[其他解释]
这样写会报错 这个OCX界面是一个UserControl
[其他解释]
我这样可以正常调用 For Each objP In UserControl.Controls 但是因为在函数中使用 调用的时候Call SaveFrmControlToIni(UserControl, "c:\text.ini", Text1.Text) 他就会提示使用的基类名称无效 如果用Me替代他就会提示未找到方法或数据成员
Public Function SaveFrmControlToIni(frm As Object, IniFileName As String, AppName As String)
Dim FrmCtr As Control Dim CtrValue As String Dim CtrName As String Dim EfficValue As String '//有效的属性.
For Each FrmCtr In frm.Controls CtrName = UCase$(FrmCtr.Name) If Len(CtrName) >= 5 Then If Mid$(CtrName, 4, 1) = "R" Or Mid$(CtrName, 4, 1) = "W" Then EfficValue = GetControlEfficValue(FrmCtr) CtrValue = VBA.CallByName(FrmCtr, EfficValue, VbGet)
WriteIniStr AppName, CtrName, CtrValue, IniFileName End If End If Next
Set FileCtr = Nothing
End Function [其他解释] 参考一下,在用户控件里可以这样写
Private Sub UserControl_Initialize() Dim objP For Each objP In UserControl.Controls Debug.Print objP.Name Next End Sub