PDA

View Full Version : Help with VBA Combo Box code in a word document



GoodGriff
01-24-2020, 07:46 AM
Hi there,

I have created a simple combo box macro in the attached word doc, the reason being the text characters I intend to use exceed the maximum allowed per regular drop-down lists.

I'm having an issue whereby the options in the list are duplicating, sometimes there are the correct number of options but I find particularly after clicking save the drop-down options become duplicated.

I am very new to VBA so I'm sure that I'm missing something fundamental here, any help or advice would be ,massively appreciated.

The code I used is below:

Private Sub ComboBox1_DropButtonClick()
ComboBox1.AddItem "Option 1"
ComboBox1.AddItem "Option 2"
ComboBox1.AddItem "Option 3"
ComboBox1.AddItem "Option 4"
ComboBox1.AddItem "Option 5 "
ComboBox1.AddItem "Option 6"
ComboBox1.AddItem "Option 7"
ComboBox1.AddItem "Option 8"
ComboBox1.AddItem "Option 9"
ComboBox1.AddItem "Option 10"
ComboBox1.AddItem "Option 11"
End Sub

gmaxey
01-24-2020, 10:04 AM
Private Sub ComboBox1_DropButtonClick()
With ComboBox1
.Clear
.AddItem "Option 1"
.AddItem "Option 2"
.AddItem "Option 3"
.AddItem "Option 4"
.AddItem "Option 5 "
.AddItem "Option 6"
.AddItem "Option 7"
.AddItem "Option 8"
.AddItem "Option 9"
.AddItem "Option 10"
.AddItem "Option 11"
End With
End Sub