我有一个带有日历的userform1。每一天都由一个标签组成。当单击标签时,调用一个类模块来标识被单击的标签并记录其标题:
Public WithEvents Frme As MSForms.Label
Public frm As UserForm
Private Sub Frme_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
'here i want call a userform2
End Sub
我需要调用userform2来显示当天的活动,但是我不能将Frme变量与userform2链接起来。我请求帮助
虽然我在网上查了很多,但我在课堂模块上没有多少知识
通过在类模块中声明一个公共变量并在调用Userform2之前设置其值,可以将所选标签的标题传递给Userform2。在Userform2模块中,您可以检索该变量的值,以显示所选日期的活动。下面是一个如何修改代码的示例:
在class模块中:
Public WithEvents Frme As MSForms。标签公共从用户的形式Public SelectedDate作为字符串Private Sub Frme_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, _ByVal X As Single, ByVal Y As Single)SelectedDate = frame。标题UserForm2。显示结束子
Userform2模块中:
Private Sub UserForm_Activate()使用SelectedDate变量检索并显示当天的活动结束子
通过在调用Userform2之前在类模块中设置SelectedDate变量的值,您可以在Userform2模块中检索它以显示当天的活动。你可以在Main模块中声明变量,但我认为在class模块中声明更好。
添加属性/公共变量SelectedDate
到UserForm2
。然后你可以这样做:
Private Sub Frme_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
Dim frm As UserForm2 'see https://rubberduckvba.wordpress.com/2017/10/25/userform1-show/
Set frm = New UserForm2 'create an instance of UserForm2
frm.SelectedDate = Frme.Caption 'or however you get the date
frm.Show 'show the instance
End Sub