[英]How will I get the last modified date of a file in a SharePoint using VBA?
I would like to seek help regarding on getting the last modified date of a file in a Sharepoint.我想寻求有关获取 Sharepoint 中文件的最后修改日期的帮助。 What VBA code/command will I use in order to execute it.
我将使用什么 VBA 代码/命令来执行它。 I would like to show this "Last Modified Date" of the file in a MsgBox when a command button is clicked.
单击命令按钮时,我想在 MsgBox 中显示文件的“上次修改日期”。
Your prompt response is very much appreciated.非常感谢您的及时回复。
This one had me scratching my head for a bit too...这个也让我摸不着头脑...
Make sure to add "@ssl" following the root URL eg确保在根 URL 后添加“@ssl”,例如
FileDateTime("\\\\site.com@ssl\\file.xlsx") FileDateTime("\\\\site.com@ssl\\file.xlsx")
I've been trying to figure this out for a while and I stumbled upon something in another line of inquiry that led me to a solution.我一直在尝试解决这个问题,并且在另一条查询线中偶然发现了一些东西,这让我找到了解决方案。
In your VBA window, go to Tools -> References, and then scroll down and check the box next to "Microsoft Scripting Runtime".在您的 VBA 窗口中,转到“工具”->“参考”,然后向下滚动并选中“Microsoft Scripting Runtime”旁边的框。
Then when you specify your link it's going to read like this:然后,当您指定链接时,它将如下所示:
FileDateTime("//site.com/page/file.xlsx
"). FileDateTime("//site.com/page/file.xlsx
").
No "http:" Once I did that, it worked like a charm.没有“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.