locked
Custom document properties Null value? RRS feed

  • Question

  • Is it possible to set document properties values at "Null"?

    I have made a template that i want to fill with properties data which has no initial value.

    Prepopulation is not desired

    Sub ResetDocProperties()
      'built-in property
      Call WriteProp(sPropName:="Author", sValue:=Null)
      Call WriteProp(sPropName:="Subject", sValue:=Null)
      Call WriteProp(sPropName:="Company", sValue:=Null)
    
      'custom document property
      Call WriteProp(sPropName:="Datum", sValue:=Null, lType:=msoPropertyTypeDate)
      Call WriteProp(sPropName:="Referentie", sValue:=Null, lType:=msoPropertyTypeString)
      Call WriteProp(sPropName:="Status", sValue:=Null, lType:=msoPropertyTypeString)
      Call WriteProp(sPropName:="Klant", sValue:=Null, lType:=msoPropertyTypeFloat)
      Call WriteProp(sPropName:="Project", sValue:=Null, lType:=msoPropertyTypeFloat)
      Call WriteProp(sPropName:="Onderwerp", sValue:=Null, lType:=msoPropertyTypeString)
      Call WriteProp(sPropName:="Taal", sValue:=Null, lType:=msoPropertyTypeString)
    End Sub
    
    Public Sub WriteProp(sPropName As String, sValue As String, _
          Optional lType As Long = msoPropertyTypeString)
    
    Dim bCustom As Boolean
    
      On Error GoTo ErrHandlerWriteProp
      ActiveDocument.BuiltInDocumentProperties(sPropName).Value = sValue
      Exit Sub
    
    Proceed:
      bCustom = True
    
    Custom:
      ActiveDocument.CustomDocumentProperties(sPropName).Value = sValue
      Exit Sub
    
    AddProp:
      On Error Resume Next
      ActiveDocument.CustomDocumentProperties.Add Name:=sPropName, _
        LinkToContent:=False, Type:=lType, Value:=sValue
    
      If Err Then
        Debug.Print "The Property " & Chr(34) & _
         sPropName & Chr(34) & " couldn't be written, because " & _
         Chr(34) & sValue & Chr(34) & _
         " is not a valid value for the property type"
      End If
    
      Exit Sub
    
    ErrHandlerWriteProp:
      Select Case Err
        Case Else
       Err.Clear
       If Not bCustom Then
         Resume Proceed
       Else
         Resume AddProp
       End If
      End Select
    
    End Sub
    

    Friday, July 8, 2016 9:02 AM

All replies

  • I figured out a simple work around :-)

    In stead of 

    sValue:=Null

    I have typed

    sValue:=""

    Friday, July 8, 2016 9:11 AM