View Single Post
 
Old 03-17-2021, 01:13 AM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,375
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

Quote:
Originally Posted by LQuinn View Post
I'm getting the properties and then putting them back into the document in alpha order
I realize that. But, as I said:
Quote:
Originally Posted by macropod View Post
I'm not convinced there's much to be gained by reinserting them in the sorted order, though.
That said, reading, capturing, deleting & reinserting the properties could likewise be done more simply and more comprehensively:
Code:
Sub Sort_Custom_Document_Properties()
Dim DocProp As DocumentProperty, CustPropArr() As String, i As Long
ReDim Preserve CustPropArr(0): CustPropArr(0) = ""
With ActiveDocument
  For Each DocProp In .CustomDocumentProperties
    With DocProp
      If InStr(1, .Name, "contenttype", vbTextCompare) = 0 Then
        ReDim Preserve CustPropArr(UBound(CustPropArr) + 1)
        CustPropArr(UBound(CustPropArr)) = .Name & "|" & .Type & "|" & .Value & "|" & .LinkToContent & "|" & .LinkSource
      End If
    End With
  Next DocProp
  For i = 1 To UBound(CustPropArr)
    .CustomDocumentProperties(Split(CustPropArr(i), "|")(0)).Delete
  Next
  WordBasic.SortArray CustPropArr
  For i = 1 To UBound(CustPropArr)
    .CustomDocumentProperties.Add _
      Name:=Split(CustPropArr(i), "|")(0), _
      Type:=Split(CustPropArr(i), "|")(1), _
      Value:=Split(CustPropArr(i), "|")(2), _
      LinkToContent:=Split(CustPropArr(i), "|")(3), _
      LinkSource:=Split(CustPropArr(i), "|")(4)
    CustPropArr(i) = Split(CustPropArr(i), "|")(0)
  Next
End With
MsgBox "The following Custom Document Properties have been sorted:" & vbCr & Join(CustPropArr, vbCr)
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote