| Member with 1 posts. THREAD STARTER | | Join Date: Jul 2012 Location: Perth Experience: Intermediate | |
How to Populate Multiple ActiveX ComboxBoxes VBA I'm building a lengthy MSWord Document with numerous activeX comboboxes on it.
There are a number of combo boxes which need to be populated with the same information, therefore I want to be able to give these a naming convention i.e. country1 country2 etc and then be able to iterise through a collection to populate the combox box with the same info. This will be run on open. Also as the document is dynamic, so on intial editing some of these comboboxes may be deleted prior to saving and closing. To ensure that when the document is open subsequently that no errors occur and if statement is also needed to check that the combobox exists before trying to populate the boxes.
Given that the collections tend work on indexes. I was going to count the collection then iterise through the collection checking to see if a trimmed name match occurs and if so then populate. However it all seems to fail for me. Below is my code.. Code: dim i as integer
dim shapesCount as integer
dim name as string
dim fullName as string
shapesCount = ActiveDocument.InlineShapes.Count
let i = 1
name = left(ActiveDocument.InlineShapes(i).Title, 7)
fullName = ActiveDocument.InlineShapes(i).Title
Do while i < shapesCount
If (combox exists) then
If name = "country"
With fullName
.Additem "Australia"
.AddItem "UK"
.AddItem "US"
.AddItem "Canada"
End with
Else
EndIf
i = i+1
EndIF
Loop |