How can I update the properties of a SharePoint content type based on values ​​in a document?

I am using an Excel Template as a custom document type in a Sharepoint Document Set. I have some custom matadats for this type of document, for example one called Priority which is a list (Low, Med, High).

I can read metadata from a document using ActiveWorkbook.ContentTypeProperties(Property)

.

Is there a way to change the value within the document? I would like to have metadata values ​​retrieved from the content of the document.

+3


source to share


1 answer


The server metadata is referenced through ContentTypeProperties, as you described. In order for them to be tied to the content of the doc, I once created a worksheet function to do this so that you specify the desired metadata name and the value you want to change, here's my code and comments -

Public Function zSETSERVERMETADATA(ByVal metaTypeName As String, Optional ByVal newValue As String = "") As String
'Recalculate upon every time any cell changes
Application.Volatile
'Set wb pointer trough caller parents
Dim wb As Workbook, r As Range, ws As Worksheet
Set r = Application.Caller
Set ws = r.Parent
Set wb = ws.Parent

'Clear unused elements
Set r = Nothing
Set ws = Nothing
On Error GoTo NoSuchProperty

'If value defined on newValue, set the value and showoutput
If newValue <> "" Then
    wb.ContentTypeProperties(metaTypeName).Value = newValue
    zSETSERVERMETADATA = wb.ContentTypeProperties(metaTypeName).Value
    Set wb = Nothing
    Exit Function
'If no value defined on newValue only show output but leave content type unchanged
Else
    zSETSERVERMETADATA = wb.ContentTypeProperties(metaTypeName).Value
    Set wb = Nothing
    Exit Function
End If

NoSuchProperty:
    zSETSERVERMETADATA = CVErr(xlErrValue)
    Set wb = Nothing
End Function

      

You can use it like any worksheet function, for example if you want to change the meta server called "Author" to the value "SickDimension" you call in the cell with the formula -



=zSETSERVERMETADATA("Author";"SickDimension")

      

Btw, with my function, leaving the second parameter empty will just return the value of that field.

+3


source







All Articles