简体   繁体   中英

How to Get Last Modified Date of excel file from Sharepoint using VBA?

I need to get the Last Modified Data of excel file to a variable from Share point.

I have excel file In sharepoint which will be updated weekly. I just need to get the lats modified date in a variable to proceed with my macro. Please Help.

Thanks in Advance!!!

Check this solution from exceluser.com:

Public Function LastSaveTime() As String
   Application.Volatile
   LastSaveTime = ThisWorkbook.BuiltinDocumentProperties("Last Save Time")
End Function

This should also work with a Workbook which is stored in a sharepoint library - just tested it with SharePoint 2010

Edit to grab data from SharePoint List:

Check this Link - there it is explained how you are able to read list data into excel.

With this Link you will be able to get the ListName and the ViewName.

With those 2 combined the easiest way would be to create a new view for the list and add only the change column to the view - when the data has been imported to excel you can read that data easily and drop the added table again.

Hope this helps to get you in the right direction. (Tested and working with SP2010 List)

Sub TestWhen()

    SPFilePath = "http://teams.MyCompany.com/sites/PATH/PATH/Fulfillment/Forms/AllItems.aspx"

    Debug.Print SPLastModified(SPFilePath, "2021_MyFileName.xlsx")

End Sub


Function SPLastModified(SPUrl As String, SPFName As String)
    Dim ie As Object
    Dim PagesHTML As String
    Dim Dadate As String
    Dim DaDateEnd As String
    Dim arr() As String
    arr = Split(OutString, " ")
 
    Dim LastChange As Variant

    Set ie = CreateObject("InternetExplorer.Application")

    With ie
        .Visible = True
        .navigate SPUrl
        Do Until .readyState = 4
            DoEvents
        Loop
    
        Do While .busy: DoEvents: Loop

        Do Until .readyState = 4
            DoEvents
        Loop
        PagesHTML = ie.document.DocumentElement.outerHTML
    End With

' Get to File
    Dadate = InStr(PagesHTML, "FileLeafRef" & Chr(34) & ": " & Chr(34) & SPFName)

' Get to Modified Date
    ModifiedText = "Modified" & Chr(34) & ": "
    Dadate = Dadate + InStr(Mid(PagesHTML, Dadate), ModifiedText)

    OutString = Mid(PagesHTML, Dadate + Len(ModifiedText), 27)

    arr = Split(OutString, " ")
   
    LastChange = arr(1) & " " & arr(2)    
    LastChange = arr(0) & "/" & Mid(arr(1), 6) & "/" & Mid(arr(2), 6, 4) & " " & LastChange

    SPLastModified = LastChange

End Function

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