Each document contains four user fields. To access them manually, click File Properties and then choose the User Defined tab. This tab contains four text fields with user information. Use the interface com.sun.star.document.XDocumentInfoSupprierto retrieve and set these text fields. The object method getDocumentInfo() returns an object that supports the interface com.sun.star.document.XDocumentInfo (see Table 4 ).
Object Method | Description |
---|---|
GetUserFieldCount() | Number of available fields. |
getUserFieldName(index) | Name of the specified field. |
getUserFieldValue(index) | Value of the specified field. |
setUserFieldName(index, name) | Set the name of the specified field. |
setUserFieldValue(index, value) | Set the value of the specified field. |
The macro in Listing 3 sets the value of a user field and then displays its value. Figure 2 shows the user-information fields in the current document.
Sub GetUserlnfoFields Dim vDocInfo 'Document Information Object Dim s$ 'General string to print Dim i% 'Index variable vDocInfo = ThisComponent.getDocumentInfo() vDocInfo.setUserFieldValue(1, "My special user value") For i% = 0 To vDocInfo().getUserFieldCount()-1 s$ = s$ & vDocInfo.getUserFieldName(i) & " = " &_ CStr(vDocInfo.getUserFieldValue(i)) & CHR$(10) Next MsgBox s$, 0, "Info Fields" End Sub