label.caption未更新

时间:2016-03-21 11:58:25

标签: excel vba excel-vba

我的vba中没什么问题。我是vba的新手。所以请帮助我解决这个问题。

我有两个像用户一样的图片。

Userform1

Userform2

userform 1的以下代码

Private Sub CommandButton1_Click()
Me.Hide
UserForm2.Show
End Sub

userform 2的以下代码

Private Sub CommandButton1_Click()
Me.Hide
UserForm1.TextBox1.Value = ""
UserForm1.Show

End Sub


Private Sub UserForm_Initialize()
Label2.Caption = UserForm1.TextBox1.Value
End Sub
问题是当我回到userform 1&在文本框中输入值,然后单击go按钮,它会重定向到userform 2,但不会更新label1.caption。

任何人都可以帮我解决如何更新label1 ?????

2 个答案:

答案 0 :(得分:2)

在userform 2上使用Useform_Activate事件。

Private Sub UserForm_Activate()
Label2.Caption = UserForm1.TextBox1.Value
Me.Repaint
End Sub

答案 1 :(得分:0)

设置值后使用Me.Repaint,这将强制表单更新其上的所有内容,并显示该值。