根据userform中的多个复选框在文本框中显示文本字符串

时间:2017-03-06 19:03:32

标签: excel excel-vba userform vba

我创建了一个包含4个复选框和1个文本框的简单用户窗体。

enter image description here

我希望能够根据点击的复选框显示句子。 如果checkSwimming池被检查,我想显示这个字符串: 打电话的人提到了游泳池。

如果选中复选框游泳池和复选框阳台,我想显示此字符串。

来电者提到游泳池。 来电者提到了阳台。

和儿子。

到目前为止,这是我的代码:

Private Sub CommandButton1_Click()

'If chkPool.Value = True Then
'txtComment.Text = "The caller asked about Swimming Pool."

'ElseIf chkBalcony.Value = True Then
'txtComment.Text = "The caller asked about Balcony and Patio."

'End If

Select Case test_test

Case chkPool.Value = True
txtComment.Text = "The caller asked about Swimming Pool."


Case chkPool.Value = True & chkBalcony.Value = True
txtComment.Text = "The caller asked about Swimming Pool."
txtComment.Text = "The caller asked about balcony."


End Select




End Sub

1 个答案:

答案 0 :(得分:0)

这是你在找什么?

Private Sub CommandButton1_Click()

txtComment.Text = ""

If chkPool.Value = True Then
    txtComment.Text = txtComment.Text & "The caller asked about Swimming Pool." & Chr(10)
End If

If chkBalcony.Value = True Then
    txtComment.Text = txtComment.Text & "The caller asked about Balcony and Patio." & Chr(10)
End If

'... add more IF clauses for the other check boxes here...


End Sub

只需确保文本框为MultiLine = True