Excel VBA:如何将组合框当前值存储到单元格

时间:2013-08-08 05:52:02

标签: excel-vba vba excel

对于登录表单,我使用下面的代码将所有文本框和组合框控件的值存储在一个单独的工作表中,填充标记和文本框值,但是单独的组合框值不会写入单元格。谁能指出我的错误?

For Each cControl In frmLogin.Controls
If cControl.Name Like "txt*" Or cControl.Name Like "cb*" Then
    Sheet5.Cells(m, 10).Value = cControl.Tag
    Sheet5.Cells(m, 11).Value = cControl.Text
    m = m + 1
End If

下一步

1 个答案:

答案 0 :(得分:0)

您必须使用MSForms进行比较。

试试这个

Dim cControl As Control
Dim m As Long

'~~> Change as applicable
m = 1

For Each cControl In frmLogin.Controls
    If TypeOf cControl Is MSForms.TextBox Or _
    TypeOf cControl Is MSForms.ComboBox Then
        Sheet5.Cells(m, 10).Value = cControl.Tag
        Sheet5.Cells(m, 11).Value = cControl.Text
        m = m + 1
    End If
Next