如何使用VBA

时间:2017-05-30 19:28:11

标签: vba sharepoint properties

enter image description here

我希望开发代码以在SharePoint上查看文件的文档属性,然后构建此代码以查看它是否与ActiveWorkbook的文档属性匹配。下面是我到目前为止的代码示例,它可以筛选到SharePoint库中的正确文档。有没有人知道必须添加到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

1 个答案:

答案 0 :(得分:0)

我假设使用SharePoint 2010及更高版本。

使用SharePoint REST服务获取具有所需属性的正确数据项。

REST Services Reference for Sharepoint 2010

REST API Reference for SharePoint 2013

使用SharePoint 2010从列表中获取项目:

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

使用SharePoint 2013从列表中获取项目

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

然后您必须使用VBA请求此网址(请记住添加对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解析适合您;)

/编辑

要使用您的文件名过滤元素,请使用:

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