2017-05-30 91 views
0

enter image description here如何使用VBA

我期待開發代碼來查看SharePoint中的文件的文檔屬性,然後再打造出這個代碼,看看它是否在ActiveWorkbook的文檔屬性相匹配,以檢查SharePoint文檔屬性。以下是我目前可以篩選到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 
+0

你是指文檔庫中文檔的sharepoint listitem屬性? – tinamou

+0

是的,與SharePoint上的文檔相關聯的屬性。如果您將其從網絡上打開,則不是文件屬性。 – Greg

回答

0

我假設SharePoint 2010及更高版本。

使用SharePoint REST Services獲取具有所需屬性的正確數據項。

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 

則Y OU有權要求該網址與VBA(remeber將引用添加到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 
+0

感謝您的幫助!只需確認,所有這些代碼都需要訪問包含在我的問題中的快照中的「標題」屬性? – Greg

+0

需要正確的REST調用。在VBA中的Web請求是必需的,也需要xml讀取:)我將更新我的代碼以匹配您的文件名過濾器 – tinamou