2014-03-26 43 views
0

1个用户窗体(UserForm1)有一个列表框(ListBox1),并且在这个列表框中有3个项目,当我双击第一个项目时,它进入UserForm2,当我双击第二个项目时,它将转到UserForm3,当我双击3项目时,它将转到UserForm4。可以点击打开另一个用户窗体的列表框选择用户窗体

+0

我不明白你的问题在哪里?告诉我们你有什么尝试,你卡在哪里? –

回答

0

私人小组ListBox1_DblClick(BYVAL取消作为MSForms.ReturnBoolean)

Dim Obj As Object 
Set Obj = VBA.UserForms.Add("UserForm" & CStr(ListBox1.ListIndex + 2)) 
Obj.Show 
Unload Obj 

结束子

参见http://www.cpearson.com/Excel/showanyform.htm

+0

谢谢。您提供的代码帮我找出我需要的代码: '如果Me.ListBox.ListIndex = 0,则 UserForm1.Show 结束如果 如果Me.ListBox.ListIndex = 1,则 UserForm2.Show 结束If' – Hush

0

这些代码可以被使用(当列表框的任何项目点击时,用户窗体另一个打开。打开的用户表单文本框根据列表框中单击的项目值填充):

Private Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean) 
Load UserForm2 
UserForm2.TextBox1 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 0) 
UserForm2.TextBox2 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 1) 
UserForm2.TextBox3 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 2) 
UserForm2.TextBox4 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 3) 
UserForm2.TextBox5 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 4) 
UserForm2.TextBox6 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 5) 
UserForm2.TextBox7 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 6) 
UserForm2.TextBox8 = VBA.Format(UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 7), "#,##.00") 
UserForm2.TextBox9 = VBA.Format(UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 8), "dd.mm.yyyy") 
UserForm2.TextBox10 = UserForm1.ListBox2.List(UserForm1.ListBox2.ListIndex, 0) 
Unload UserForm1 
UserForm2.Show 
End Sub 

screenshot

相关问题