'Read custom attributes
| The code is as follows: |
Copy code |
Dim Properties = SourceDoc. CustomDocumentProperties Dim PropertyType As Type = Properties. GetType Try Dim Authorprop = PropertyType. InvokeMember ("Item", Reflection. BindingFlags. Default Or Reflection. BindingFlags. GetProperty, Nothing, Properties, New Object () {"remarks "}) ResultString = Authorprop. GetType. InvokeMember ("Value", Reflection. BindingFlags. Default Or Reflection. BindingFlags. GetProperty, Nothing, Authorprop, New Object (){}) Catch ex As Exception End Try 'Write Dim Authorprop = PropertyType. InvokeMember ("Item", Reflection. BindingFlags. Default Or Reflection. BindingFlags. SetProperty, Nothing, properties, New Object () {"remarks", ResultString }) |
Another method
'Add new property
| The code is as follows: |
Copy code |
| SourceDoc. CustomDocumentProperties. Add (Name: = "PropertyName", LinkToContent: = False, Type: = Microsoft. Office. Core. MsoDocProperties. msoPropertyTypeString, Value: = "PropertyValue ") |
'Modify attributes
| The code is as follows: |
Copy code |
SourceDoc. CustomDocumentProperties ("PropertyName"). Value = PropertyValue |
'Get the property value
| The code is as follows: |
Copy code |
| PropertyValue = SourceDoc. CustomDocumentProperties ("PropertyName"). Value |
After reading the write operation, you can right-click the word document and choose Properties to view the effect. However, when the word document is open, right-click the document and there is no "custom" or "abstract" Tab.