我想一起添加两个文本框

时间:2015-07-28 14:45:37

标签: vba textbox

我有2个文本框和一个标签。

我希望能够在标签中显示两个文本框的连接文本。我使用了以下代码:

Private Sub CommandButton1_Click()

    Label1.Text = Val(TextBox1.Text) + Val(TextBox2.Text)  

End Sub

然而,这并不起作用,我正在

  

编译错误:找不到方法或数据成员

有人可以解释为什么会发生这种情况以及如何解决这个问题吗?

3 个答案:

答案 0 :(得分:1)

In a Macro enabled excel file, add the activeX version of command button, text boxes and label.

After this you can have your desired result with this code:

Private Sub CommandButton1_Click()
Label1.Caption = TextBox1.Text & TextBox2.Text
End Sub

Please check that the macros are saved correctly. This solution works on Excel 2013.

答案 1 :(得分:0)

如果要在VBA中连接文本,请使用&符号(&)。 .Text方法只是提取值。以下对我有用。

Private Sub CommandButton1_Click()
    Label1 = TextBox1.Text & TextBox2.Text
End Sub 

答案 2 :(得分:0)

试试这个,亲爱的。

txtTotal = val(me.text1)+ val(me.text2)

相关问题