Möglicherweise habe ich wieder Tomaten auf den Augen, aber es funktioniert jetzt alles, solange ich Strings zum Speichern benutze. Der Versuch mit einem Long scheitert aber.
Code: Alles auswählen
Option Explicit
Sub Main
Dim sName As String, vValue As Variant : sName = "iMillisecWait" : vValue = CLng(400)
MsgBox putDocUsrProp(sName, vValue)
End Sub
Function putDocUsrProp(sPropName As String, vPropValue As Variant, Optional vDoc As Variant) As Boolean
'create the userdefined property sPropName if it does not exist and set it to vPropValue
'On Error GoTo Err_putDocUsrProp:
Dim oDoc As Variant
If IsMissing(vDoc) Then
oDoc = ThisComponent
Else
oDoc = vDoc
End If
Dim oUDP As Variant
oUDP = oDoc.getDocumentProperties().UserDefinedProperties
If NOT oUDP.getPropertySetInfo().hasPropertyByName(sPropName) Then
oUDP.addProperty(sPropName, _
com.sun.star.beans.PropertyAttribute.MAYBEVOID + _
com.sun.star.beans.PropertyAttribute.REMOVEABLE + _
com.sun.star.beans.PropertyAttribute.MAYBEDEFAULT,"")
End If
oUDP.setPropertyValue(sPropName, vPropValue)
If vPropValue = oUDP.getPropertyValue(sPropName) Then putDocUsrProp = True
Exit_putDocUsrProp:
Exit Function
Err_putDocUsrProp:
Print StdErrMsg & CStr(Err) & " in Line " & CStr(Erl) & Chr$(10) & Error$, 16, "miscutilsLib.docpropsMod.putDocUsrProp"
Resume Exit_putDocUsrProp
End Function
[attachment=0]the-given-value-can-not-be-converted-to-the-required-property-type.png[/attachment]