Advertisement
kijato

Word, VBA, ListOfDocumentProperties

Dec 2nd, 2021
1,818
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub CommandButton1_Click()
  2.  
  3. ActiveDocument.Content.Delete
  4.  
  5. Dim countOfProperties As Integer
  6. Dim counter As Integer
  7.  
  8. ActiveDocument.Content.InsertAfter Text:="BuiltInDocumentProperties" & vbNewLine
  9.  
  10. For Each fileProperty In ActiveDocument.BuiltInDocumentProperties
  11.     countOfProperties = countOfProperties + 1
  12.     On Error Resume Next
  13.     Debug.Print fileProperty.Name & ": " & fileProperty.Value
  14. Next fileProperty
  15.  
  16. Set tblNew = ActiveDocument.Tables.Add(Selection.Range, countOfProperties, 3)
  17. With tblNew
  18.   For Each fileProperty In ActiveDocument.BuiltInDocumentProperties
  19.     counter = counter + 1
  20.     .Cell(counter, 1).Range.InsertAfter counter
  21.     .Cell(counter, 2).Range.InsertAfter fileProperty.Name
  22.     On Error Resume Next
  23.     .Cell(counter, 3).Range.InsertAfter fileProperty.Value
  24.   Next fileProperty
  25.   .Columns.AutoFit
  26. End With
  27.  
  28.  
  29. ActiveDocument.Content.InsertAfter Text:="CustomDocumentProperties" & vbNewLine
  30.  
  31. For Each fileProperty In ActiveDocument.CustomDocumentProperties
  32.     countOfProperties = countOfProperties + 1
  33.     On Error Resume Next
  34.     Debug.Print fileProperty.Name & ": " & fileProperty.Value '& vbNewLine
  35. Next fileProperty
  36.  
  37. End Sub
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement