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
. 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. Does anyone know the function which must be added to objFile
to access the SharePoint Document properties?
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.
Use SharePoint REST Services to get proper data items with desired properties.
REST Services Reference for Sharepoint 2010
REST API Reference for SharePoint 2013
Get items from list using 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
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
)
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 ;)
/edit
To filter element with your filename, use:
http://lab/_vti_bin/listdata.svc/Library()?$filter=FileLeafRef eq 'FileName.zip'&$select=Title
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.