View Single Post
 
Old 03-17-2021, 12:36 AM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Your code could be greatly simplified. For example, to produce an alpha-sorted Custom Document Property list:
Code:
Sub Sort_Custom_Document_Properties()
Dim DocProp As DocumentProperty, CustPropArr() As String
ReDim Preserve CustPropArr(0): CustPropArr(0) = ""
' Add Custom Document Properties to Array
For Each DocProp In ActiveDocument.CustomDocumentProperties
  With DocProp
    If InStr(1, .Name, "contenttype", vbTextCompare) = 0 Then
      ReDim Preserve CustPropArr(UBound(CustPropArr) + 1)
      CustPropArr(UBound(CustPropArr)) = .Name & "|" & .Type & "|" & .Value
    End If
  End With
Next DocProp
WordBasic.SortArray CustPropArr
MsgBox Join(CustPropArr, vbCr)
End Sub
Note that the above code also explicitly captures the property type.

I'm not convinced there's much to be gained by reinserting them in the sorted order, though.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote