2014-03-26 40 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

相關問題