vba 在两个用户窗体之间传递 TextBox 值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28315800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Passing TextBox value between two UserForms
提问by Reeve
I have two user forms in Excel VBA. I enter a value in the TextBox
at the first UserForm
. How do I pass the value to the second UserForm
to display same value in a TextBox
too?
我在 Excel VBA 中有两个用户表单。我TextBox
在第一个中输入一个值UserForm
。如何将值传递给第二个UserForm
以在 a 中显示相同的值TextBox
?
回答by Amen Jlili
Assuming that your forms are named:
假设您的表单被命名为:
Userform1
for this first formUserform2
for the second form
Userform1
对于第一种形式Userform2
对于第二种形式
And assuming that you have two textboxes one in each form as follow:
并假设您有两个文本框,每种形式一个,如下所示:
TextBox1
for the first textbox located in your first formTextBox2
for the second textbox located in the second form
TextBox1
对于位于第一个表单中的第一个文本框TextBox2
对于位于第二个表单中的第二个文本框
You assign the value of the first TextBox1
to TextBox2
using Userform2.TextBox2.Text=Userform1.TextBox1.Text
您将第一个的值分配TextBox1
给TextBox2
usingUserform2.TextBox2.Text=Userform1.TextBox1.Text
回答by Jake Duddy
You can declare a public variable:
您可以声明一个公共变量:
i.e X
. In user form 1 x=textbox1.value
and in user form2 textbox2.value=X
.
即X
。在用户表单 1x=textbox1.value
和用户表单 2中textbox2.value=X
。