I am creating a PowerPoint in which I want users to be able to select an item from a list i开发者_如何学Pythonn a combo box. Nothing needs to happen after this, it is just to provide a record, on screen, of their choice.
My problem is that I seem to either be able to populate the combo box and users can select an item but the list gets longer each time the combobox is clicked on (i.e each time it is clicked on the list gets duplicated). Or alternatively, I can clear the combo box, then populate it but in this scenario, the users choice also seems to get cleared.
VBA example 1:
Private Sub ComboBox1_DropButtonClick()
With ComboBox1
.AddItem " ", 0
.AddItem "speed", 1
.AddItem "provisionality", 2
.AddItem "automation", 3
.AddItem "replication", 4
.AddItem "communicability", 5
.AddItem "multi-modality", 6
.AddItem "non-linearity", 7
.AddItem "capacity", 8
.AddItem "interactivity", 9
End With
End Sub
VBA example 2:
Private Sub ComboBox1_DropButtonClick()
ComboBox1.Clear
With ComboBox1
.AddItem " ", 0
.AddItem "speed", 1
.AddItem "provisionality", 2
.AddItem "automation", 3
.AddItem "replication", 4
.AddItem "communicability", 5
.AddItem "multi-modality", 6
.AddItem "non-linearity", 7
.AddItem "capacity", 8
.AddItem "interactivity", 9
End With
End Sub
Can anyone help?
Because you have your code in the DropButtonClick event, every time you click the dropdown, those items are being added to your combobox. Try adding some code to check if the combobox is already populated before it adds the items:
Private Sub ComboBox1_DropButtonClick()
If ComboBox1.ListCount = 0 Then
With ComboBox1
.AddItem " ", 0
.AddItem "speed", 1
.AddItem "provisionality", 2
.AddItem "automation", 3
.AddItem "replication", 4
.AddItem "communicability", 5
.AddItem "multi-modality", 6
.AddItem "non-linearity", 7
.AddItem "capacity", 8
.AddItem "interactivity", 9
End With
End If
End Sub
Then you don't have to clear the combobox and clear the selected item along with it.
If the combobox items don't change, you only need to run the code once on a macro enable pptm file.
Private Sub SetupCombo()
' set the combobox1
ComboBox1.Clear
With ComboBox1
.AddItem " ", 0
.AddItem "speed", 1
.AddItem "provisionality", 2
.AddItem "automation", 3
.AddItem "replication", 4
.AddItem "communicability", 5
.AddItem "multi-modality", 6
.AddItem "non-linearity", 7
.AddItem "capacity", 8
.AddItem "interactivity", 9
End With
End Sub
Private Sub ComboBox1_Click()
' no code need here
End Sub
Run the code by setting the cursor inside SetupCombo() and press play in the bar.
Present, check if the combo is okay and save the presentation as pptx (no need for vba or macro code). Your presentation is ready.
精彩评论