Private Sub Form_Load() Dim objForm As Form Dim objCtrl As Control
' ' 获取窗体对象 ' Set objForm = GetForm(hWnd)
If Not objForm Is Nothing Then ' ' 遍历窗体控件集合 ' For Each objCtrl In objForm.Controls ' ' 控件为编辑框类型,输出控件名称和编辑框内容 ' If TypeOf objCtrl Is TextBox Then Debug.Print "TextBox Name: " & objCtrl.Name & " Text: " & objCtrl.Text End If Next End If End Sub' ' 依据窗体句柄返回 form对象 ' Private Function GetForm(ByVal wndHandle As Long) As Form Dim frm As Form
For Each frm In Forms If frm.hWnd = wndHandle Then Set GetForm = frm Exit Function End If Next End Function
Private Sub Form_Load()
Dim objForm As Form
Dim objCtrl As Control
'
' 获取窗体对象
'
Set objForm = GetForm(hWnd)
If Not objForm Is Nothing Then
'
' 遍历窗体控件集合
'
For Each objCtrl In objForm.Controls
'
' 控件为编辑框类型,输出控件名称和编辑框内容
'
If TypeOf objCtrl Is TextBox Then
Debug.Print "TextBox Name: " & objCtrl.Name & " Text: " & objCtrl.Text
End If
Next
End If
End Sub'
' 依据窗体句柄返回 form对象
'
Private Function GetForm(ByVal wndHandle As Long) As Form
Dim frm As Form
For Each frm In Forms
If frm.hWnd = wndHandle Then
Set GetForm = frm
Exit Function
End If
Next
End Function