I came up with some code, but I doubt it's the most efficient, do you mind taking a look and telling me how you'd do it?
I want to fill a combo box on a user form (cboName) with all the names of the objects on the page. My difficulty was making sure I didn't use the same name twice. I tried using a collection first, but I didn't figure it out so I went back to an Array to do it.
Like I said it works, but I'd like some input to make it prettier and more efficient.
Code:
Sub FillList()
Dim s As Shape, sr As ShapeRange, vName As String, vNameAry() As Variant, vTemp, i As Integer, vFound As Boolean
Dim j As Integer
Set sr = ActivePage.FindShapes
If sr.Count = 0 Then
MsgBox "No objects on page. Only run this when there are objects to rename/select."
Unload Me
End
End If
ReDim vNameAry(sr.Count)
j = 1
For Each s In sr
vName = s.ObjectData("Name").Value
vFound = False
For i = 1 To j
If vName = vNameAry(i) Then
vFound = True
Exit For
End If
Next i
If vName <> "" And Not vFound Then
vNameAry(j) = vName
j = j + 1
cboName.AddItem vName
End If
Next s
End Sub
Shaddy