繁体   English   中英

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

[英]How will I get the last modified date of a file in a SharePoint using VBA?

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

非常感谢您的及时回复。

这个也让我摸不着头脑...

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

FileDateTime("\\\\site.com@ssl\\file.xlsx")

您可以使用

FileDateTime ( file_path )

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

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

VBA 帮助

我一直在尝试解决这个问题,并且在另一条查询线中偶然发现了一些东西,这让我找到了解决方案。

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

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

FileDateTime("//site.com/page/file.xlsx ").

没有“http:”一旦我这样做了,它就像一个魅力。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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