Before reading data, you must create a reference to the Word, open the file, and obtain the Document Object of the Word.
It must be noted that the length of a Word custom attribute can be limited to about 255 characters.
'Read Custom Attributes
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 attribute SourceDoc. customDocumentProperties. add (Name: = "PropertyName", LinkToContent: = False, Type: = Microsoft. office. core. msoDocProperties. msoPropertyTypeString, Value: = "PropertyValue") 'modifies the SourceDoc attribute. customDocumentProperties ("PropertyName "). value = PropertyValue 'get the property Value PropertyValue = SourceDoc. customDocumentProperties ("PropertyName "). value
'Read the built-in attributes. The following uses the remarks as an example: ResultString = SourceDoc. BuiltInDocumentProperties (Microsoft. Office. Interop. Word. WdBuiltInProperty. wdPropertyComments). 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.