如何使用VBA从Sharepoint获取excel文件的上次修改日期?

时间:2014-10-14 08:45:10

标签: excel-vba sharepoint vba excel

我需要将excel文件的Last Modified Data从Share point获取为变量。

我有excel文件在sharepoint中,每周更新一次。我只需要在变量中获取lats修改日期以继续我的宏。请帮助。

提前致谢!!!

2 个答案:

答案 0 :(得分:0)

检查this solution from exceluser.com:

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

这也适用于存储在sharepoint库中的工作簿 - 只是使用SharePoint 2010进行测试

编辑以从SharePoint列表中获取数据:

检查此Link - 在那里解释了如何将列表数据读入Excel。

使用此Link,您将能够获取ListName和ViewName。

使用这两个组合最简单的方法是为列表创建一个新视图并仅将更改列添加到视图中 - 当数据导入到Excel时,您可以轻松读取该数据并再次删除添加的表

希望这有助于让您朝着正确的方向前进。 (经过测试和使用SP2010列表)

答案 1 :(得分:0)

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
相关问题