我在论坛中搜索了这个并找到了一些答案,但对我没有用。
我有两个UserForms。
在第一个中,我给一个名为Word的变量赋值。
在第二个中,我有一个标签,我需要标题才能成为变量Word。
示例:
Public Word as String
Private Sub Userform1_Activate
Word = "Today Is Saturday"
End Sub
Private Sub Userform2_Activate
Label1.Caption = Word
End Sub
但这不起作用。标签标题的值为零。 有人可以帮我吗?
感谢。
First Form
Private Sub CommandButton5_Click()
Db = "C:\Users\Desktop\db.txt"
Set File1 = CreateObject("Scripting.FileSystemObject")
Set File2 = File1.OpenTextFile(Db, 1)
Do Until File2.AtEndOfStream
If (File2.Readline = TextBox1) Then Exit Do
If File2.AtEndOfStream Then WordNotFound.Show
If File2.AtEndOfStream Then TextBox1.Value = ""
If File2.AtEndOfStream Then Exit Sub
Loop
Word = File2.Readline
MsgBox Word
TextBox1.Value = ""
End Sub
第二表格
Private Sub UserForm_Click()
Label1.Caption = Word
End Sub
答案 0 :(得分:5)
正如我在评论中所说,你的方法应该有效。这是我试过的测试代码
1-在Module1
Public Word As String
2-创建2个用户表单 - UserForm1
和UserForm2
2a-在UserForm1中
Private Sub UserForm_Activate()
Word = "This is Saturday"
End Sub
2b-在UserForm2中
Private Sub UserForm_Activate()
Label1.Caption = Word
End Sub
3-然后在ThisWorkbook
Private Sub Workbook_Open()
UserForm1.Show
UserForm2.Show
End Sub
因此,当您关闭UserForm1时,UserForm2将显示如下