我正在Excel VBA上編寫腳本UserForm
。該表格有三個不同的字段,即ComboBox
由用戶填寫。我想要使ComboBox 3
的內容取決於在Combobox2
中輸入的內容。如何凍結ComboBox Excel VBA
ComboBox2
填充如下:
With ComboBox2
.AddItem "Legal Information"
.AddItem "Media"
.AddItem "Official Disclosures"
.AddItem "Patents and Trademarks"
.AddItem "Private Corporate Information"
.AddItem "Private Individual Information"
.AddItem "Property Information"
.AddItem "Public Company Information"
.AddItem "Public Tenders"
.AddItem "Ships, Vessels and Aircraft Information"
.AddItem "Watchlists/Blacklists"
End With
根據什麼ComboBox2
用戶輸入,ComboBox3
是由不同的選擇填充。我做的,例如如下:
Private Sub ComboBox2_Change()
Dim index As Integer
index = ComboBox2.ListIndex
ComboBox3.Clear
Select Case index
Case Is = 0
With ComboBox3
.AddItem "Administrative"
.AddItem "Civil"
.AddItem "Criminal"
End With
Case Is = 1
With ComboBox3
.AddItem "Arts and Culture"
.AddItem "Blog/Social Media"
.AddItem "Business and Economics"
.AddItem "General News"
.AddItem "Intelligence and Security"
.AddItem "Official News Agency/Official Press"
.AddItem "Energy"
.AddItem "Pharmaceutical and Medical News"
.AddItem "Politics"
.AddItem "Religion"
.AddItem "Society, Lifestyle and Opinion"
.AddItem "Sport"
End With
End Sub
我想爲ComboBox3
被凍結,也就是說,不可能爲用戶填寫,在任何其他的ComboBox2
選項被選中的情況下 - 在事件Case is = 2, 3, 4, 5, 6, 7, 8, 9, 10
。我應該如何做到這一點。謝謝。
'ComboBox3.Enabled = False'? – CMArg
使用鎖定或鎖定使用.enabled –
FWIW'Case Is = 0'可以更簡單地寫爲'Case 0'。 –