简体   繁体   中英

Is there a way to retrieve file metadata from Sharepoint using VBA in excel without having to open each file?

My goal is to present my users a method of previewing the details of files stored on Sharepoint from within a VBA userform in excel. So far I am able to retrieve a list of files using Scripting.FileSystemObject .

I'm aware I could use ContentTypeProperties to access the information I want but this appears to be dependent on opening each file. Is there some other method I could use which would allow me to access the metadata without having to open each file?

I'm not an avid user of Sharepoint so please excuse my use of terminology.

I'm walking in to uncharted territory in respect to my own understanding here so any help or pointers to further reading would be much appreciated.

Thank you!

edit: Existing code relying on Scripting.FileSystemObject to retrieve filename only.

Private Sub UserForm_Activate()
Dim spURL As String
Dim oFile As Object, oFSO As Object, oFldr As Object, oFiles As Object, oDSO As Object
Dim ext As String, title As String
spURL = **sharepoint url**

Set oFSO = CreateObject("Scripting.Filesystemobject")
Set oFldr = oFSO.getfolder(spURL)
Set oFiles = oFldr.Files

For Each oFile In oFiles
    If InStr(1, ext, "xls") Then
        Me.cboFiles.AddItem oFile.Name
    End If  
Next
Set oFSO = Nothing
Set oFldr = Nothing
Set oFiles = Nothing
End Sub

Now lets say I wanted to get document type, which is a custom field in the document properties when the files are checked in to sharepoint, I'm aware I could do something like:

set wb = workbooks.open(spURL & oFile.Name)
debug.print wb.ContentTypeProperties.Item(x).Value

(Where Item(x) is relative to the field I need to pull information from) However, what I'm looking to determine is if there is an alternative method which doesn't require the workbook to be open.

Digging in to things a little deeper I have found the following on http://www.cpearson.com/excel/docprop.aspx : "VBA doesn't directly support reading properties from closed files. However, Microsoft has made available for free download a DLL file called DSO OLE Document Properties Reader 2.1, or simply DSOFile.dll. With this DLL, you can read both BuiltIn and Custom properties from a OLE file, such as an XLS workbook."

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.

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