vba 如何根据文档中的值更新 SharePoint 内容类型属性?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25441521/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I update SharePoint content type properties, based on values in the document?
提问by Matt
I'm using an Excel template as a custom document type in a Sharepoint Document Set. I have some custom matadata for this document type, for instance one called Priority, which is a list (Low, Med, High).
我使用 Excel 模板作为 Sharepoint 文档集中的自定义文档类型。我有一些针对这种文档类型的自定义元数据,例如一个称为优先级的数据,它是一个列表(低、中、高)。
I can read the metadata from within the document using ActiveWorkbook.ContentTypeProperties(Property)
.
我可以使用ActiveWorkbook.ContentTypeProperties(Property)
.
Is there any way to change the value from within the document? I would like to have the metadata values derived from document content.
有没有办法从文档中更改值?我想要从文档内容派生的元数据值。
采纳答案by Han Soalone
Refering to server metadata happens via ContentTypeProperties as you described. For them to be feched from doc content, I once created a worksheet function to do this that you tell the wanted metadata name and the value you wish it to be changed, here's my code and comments -
如您所述,通过 ContentTypeProperties 引用服务器元数据。为了从文档内容中获取它们,我曾经创建了一个工作表函数来执行此操作,您可以告诉所需的元数据名称和您希望更改的值,这是我的代码和注释 -
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 instance if you want to change server meta called "Author" to value "SickDimension" you call the function in cell with formula -
您可以像使用任何工作表函数一样使用它,例如,如果您想将名为“Author”的服务器元更改为值“SickDimension”,您可以使用公式在单元格中调用该函数 -
=zSETSERVERMETADATA("Author";"SickDimension")
Btw, with my function, leaving the second parameter empty will just return the value of that field.
顺便说一句,对于我的函数,将第二个参数留空只会返回该字段的值。