G
Greg Maxey
I am trying to build a list of ContentControls in a document by unique
Titles. That is if there are two or more CCs with the same title I only
want to list it once. I am using a Collection and the key method to ensure
the CCs title is only added one time. Then I am stepping through the
members of the collection one at a time to add them to an Array. Is there a
more direct method to convert a collection to an array?
Sub ScratchMacro()
Dim oCC As ContentControl
Dim oColl As Collection
Set oColl = New Collection
Dim i As Long
Dim tempList() As String
For Each oCC In ActiveDocument.ContentControls
If oCC.Title <> "" Then
Select Case oCC.Type
Case Is = 1, 3, 4, 6 'CCs of type text, dropdown, combobox, and date
only
'Use error on duplicate key to ensure only unique titles are added.
On Error Resume Next
oColl.Add oCC.Title, oCC.Title
On Error GoTo 0
Case Else
'Do Nothing
End Select
End If
Next
If oColl.Count > 0 Then
'Create array from collection.
ReDim tempList(oColl.Count - 1)
'Is there a more direct method to populate an array with collection
elements?
For i = 0 To oColl.Count - 1
tempList(i) = oColl(i + 1)
Next
Else
ReDim tempList(0)
tempList(0) = "****Empty List****"
End If
'Sort array alphabetically
WordBasic.SortArray tempList
End Sub
Titles. That is if there are two or more CCs with the same title I only
want to list it once. I am using a Collection and the key method to ensure
the CCs title is only added one time. Then I am stepping through the
members of the collection one at a time to add them to an Array. Is there a
more direct method to convert a collection to an array?
Sub ScratchMacro()
Dim oCC As ContentControl
Dim oColl As Collection
Set oColl = New Collection
Dim i As Long
Dim tempList() As String
For Each oCC In ActiveDocument.ContentControls
If oCC.Title <> "" Then
Select Case oCC.Type
Case Is = 1, 3, 4, 6 'CCs of type text, dropdown, combobox, and date
only
'Use error on duplicate key to ensure only unique titles are added.
On Error Resume Next
oColl.Add oCC.Title, oCC.Title
On Error GoTo 0
Case Else
'Do Nothing
End Select
End If
Next
If oColl.Count > 0 Then
'Create array from collection.
ReDim tempList(oColl.Count - 1)
'Is there a more direct method to populate an array with collection
elements?
For i = 0 To oColl.Count - 1
tempList(i) = oColl(i + 1)
Next
Else
ReDim tempList(0)
tempList(0) = "****Empty List****"
End If
'Sort array alphabetically
WordBasic.SortArray tempList
End Sub