如何使用VBA获取SharePoint中文件的上次修改日期?

时间:2015-01-19 08:31:25

标签: excel vba excel-vba sharepoint sharepoint-2013

我想就获取Sharepoint中文件的最后修改日期寻求帮助。我将使用什么VBA代码/命令来执行它。 我想在单击命令按钮时在MsgBox中显示该文件的“上次修改日期”。

非常感谢您的及时回复。

4 个答案:

答案 0 :(得分:1)

这个让我有点挠头......

确保在根URL之后添加“@ssl”,例如

FileDateTime( “\\ site.com@ssl \ file.xlsx”)

答案 1 :(得分:0)

您可以使用

FileDateTime ( file_path )

获取创建或上次修改文件的日期和时间。

欲了解更多信息,请访问以下链接..

VBA Help

答案 2 :(得分:0)

我一直在努力解决这个问题,我偶然发现了另一条问题导致我找到解决方案。

在您的VBA窗口中,转到工具 - >引用,然后向下滚动并选中" Microsoft Scripting Runtime"旁边的框。

然后,当您指定链接时,它将如下所示:

FileDateTime("//site.com/page/file.xlsx&#34)。

否" http:"一旦我这样做,它就像一个魅力。

答案 3 :(得分:0)

Sub TestWhen()

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

    MsgBox SPFileName  & " last modified on" & SPLastModified(SPFilePath, SPFileName)

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