我想将两个文本框添加在一起 [英] I want to add two textboxes together
问题描述
我有 2 个文本框和一个标签.
I have 2 text boxes and a label.
我希望能够在标签中显示两个文本框的连接文本.我使用了以下代码:
I want to be able to display in a label the concatenated text of the two textboxes. I have used the following code:
Private Sub CommandButton1_Click()
Label1.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
End Sub
然而,这不起作用,我得到了
This doesn't work, however, and I am getting
编译错误:未找到方法或数据成员
Compile error: Method or data member not found
有人可以解释一下为什么会发生这种情况以及我该如何解决吗?
Can somebody explain why this is happening and how I can fix it, please?
推荐答案
在启用宏的 excel 文件中,添加 activeX 版本的命令按钮、文本框和标签.
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
请检查宏是否正确保存.此解决方案适用于 Excel 2013.
Please check that the macros are saved correctly. This solution works on Excel 2013.
这篇关于我想将两个文本框添加在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!