【问题标题】:Userform2.initialize where textbox1.value = combobox1.value from userform1Userform2.initialize where textbox1.value = combobox1.value from userform1
【发布时间】:2020-09-26 01:38:33
【问题描述】:

我有两个用户表单。在 userform1 中,设置“x”值的脚本是:

Private Sub Combobox1_Change()
    x = Combobox1.Value + 2
End Sub

我需要 userform2 使用来自 userform1 的 textbox1.value = x 进行初始化。

我什至不知道从哪里开始。关于如何做到这一点的任何见解?

编辑:我正在为 userform2 尝试以下代码:

Private Sub UserForm_Initialize()
    x = userform1.combobox1.Value
    textbox1.Value = x
End Sub

用户窗体初始化正常,但 textbox1.Value 工作正常。

【问题讨论】:

  • 我认为你不必在 UserForm1 中有 Private Sub Combobox1_Change(),但在 UserForm2 初始化时,有这样的行 textbox1.Value = userform1.combobox1.Value + 2
  • 您在哪里以及如何拨打userform2?您还应该显示此代码。但是,在大多数情况下,在另一个用户表单中调用用户表单的default instance 并不是一个好主意。也许与一个用户一起工作并使用框架、多页或类似的东西会更容易。用户甚至不会注意到他仍然使用相同的用户表单。

标签: excel vba combobox textbox userform


【解决方案1】:

您可以直接从组合框中获取值。即使不再可见,它也会有值。

用户窗体2:

Private Sub UserForm_Initialize()
    Me.TextBox1.Value = UserForm1.ComboBox1.Value + 2
End Sub

我也写信来测试它: 在一个模块中:

Sub test()
    UserForm1.Show 'I just had a fix value in the combobox for the test
    UserForm2.Show
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-16
    • 2015-08-01
    • 2013-01-05
    • 1970-01-01
    • 1970-01-01
    • 2022-12-01
    相关资源
    最近更新 更多