简体   繁体   English

如何使用VBA检查Sharepoint文档属性

[英]How to check Sharepoint Document Properties using VBA

在此处输入图片说明

I am looking to develop code to view the document properties of a file on SharePoint, then later build out this code to see if it matches the document properties of the ActiveWorkbook . 我正在寻找开发代码以查看SharePoint上文件的文档属性,然后稍后构建此代码以查看它是否与ActiveWorkbook的文档属性匹配。 Below is a sample of the code I have so far which is able to filter through to the correct document in the SharePoint Library. 下面是到目前为止我拥有的代码示例,该代码能够筛选到SharePoint库中的正确文档。 Does anyone know the function which must be added to objFile to access the SharePoint Document properties? 有谁知道必须添加到objFile才能访问SharePoint文档属性?

Sub CheckVersion()
Dim FSO As Object
Set FSO = CreateObject("Scripting.FileSystemObject")

Dim objFile As Object
Dim objDSO As Object

For Each objFile In FSO.GetFolder("\\SharePoint\Library\").Files
    If objFile.Name = "FileName.zip" Then
        MsgBox (objFile.Properties.Title)
    End If
Next

End Sub

I am assuming SharePoint 2010 and higher version. 我假设使用SharePoint 2010和更高版本。

Use SharePoint REST Services to get proper data items with desired properties. 使用SharePoint REST服务获取具有所需属性的正确数据项。

REST Services Reference for Sharepoint 2010 Sharepoint 2010的REST服务参考

REST API Reference for SharePoint 2013 SharePoint 2013的REST API参考

Get items from list using SharePoint 2010: 使用SharePoint 2010从列表中获取项目:

http://lab/_vti_bin/listdata.svc/List1()?$filter=startswith(Title,'foo')&$top=1&$select=Title,Column2,Column3

Get items from list using SharePoint 2013 使用SharePoint 2013从列表中获取项目

http://lab/_api/web/lists/getbytitle('List1')/items?$filter=startswith(Title,'foo')&$top=1&$select=Title,Column2,Column3

Then you have to request this url with VBA (remeber to add references to Microsoft WinHTTP Services, version 5.1 and Microsoft XML, v6.0 ) 然后,您必须使用VBA请求此URL(注意添加对Microsoft WinHTTP Services, version 5.1Microsoft XML, v6.0引用)

URL = "http://lab/_vti_bin/listdata.svc/List1()?$filter=startswith(Title,'foo')&$top=1&$select=Title,Column2,Column3"

Set req = CreateObject("WinHttp.WinHttpRequest.5.1")
req.Open "GET", URL, False
req.setRequestHeader "Content-Type", "application/xml"
req.SetCredentials "login", "pass", 0
req.Send

Set objXML = CreateObject("Msxml2.DomDocument.6.0")
If Not objXML.LoadXML(req.ResponseText) Then
    Err.Raise objXML.parseError.ErrorCode, , objXML.parseError.reason
End If

XML parsing is for you ;) XML解析适合您;)

/edit /编辑

To filter element with your filename, use: 要使用文件名过滤元素,请使用:

http://lab/_vti_bin/listdata.svc/Library()?$filter=FileLeafRef eq 'FileName.zip'&$select=Title

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM