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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 06:05:38  来源:igfitidea点击:

Passing TextBox value between two UserForms

excelvbaexcel-vba

提问by Reeve

I have two user forms in Excel VBA. I enter a value in the TextBoxat the first UserForm. How do I pass the value to the second UserFormto display same value in a TextBoxtoo?

我在 Excel VBA 中有两个用户表单。我TextBox在第一个中输入一个值UserForm。如何将值传递给第二个UserForm以在 a 中显示相同的值TextBox

回答by Amen Jlili

Assuming that your forms are named:

假设您的表单被命名为:

  • Userform1for this first form
  • Userform2for the second form
  • Userform1对于第一种形式
  • Userform2对于第二种形式

And assuming that you have two textboxes one in each form as follow:

并假设您有两个文本框,每种形式一个,如下所示:

  • TextBox1for the first textbox located in your first form
  • TextBox2for the second textbox located in the second form
  • TextBox1对于位于第一个表单中的第一个文本框
  • TextBox2对于位于第二个表单中的第二个文本框

You assign the value of the first TextBox1to TextBox2using Userform2.TextBox2.Text=Userform1.TextBox1.Text

您将第一个的值分配TextBox1TextBox2usingUserform2.TextBox2.Text=Userform1.TextBox1.Text

回答by Jake Duddy

You can declare a public variable:

您可以声明一个公共变量:

i.e X. In user form 1 x=textbox1.valueand in user form2 textbox2.value=X.

X。在用户表单 1x=textbox1.value和用户表单 2中textbox2.value=X