【问题标题】:VBA for-loop over specific files and confirm dateVBA for循环特定文件并确认日期
【发布时间】:2020-02-25 09:53:15
【问题描述】:

我有三个工作簿(Book1、Book2、Book3)都保存为 xlsx 文件。每天,这些工作簿都会更新。假设所有工作簿都属于以下目录:C:\Users\abc\Documents\Example,其中还包含许多其他文件(d、e、f....等)。我需要检查 Book1、Book2、Book3 是否已更新,以便“修改日期”=今天的日期。如果修改日期不等于今天的日期,我需要代码停止运行并警告“日期不正确”。我想这个任务将涉及运行一个 for 循环,但我对 VBA 很陌生。

【问题讨论】:

标签: excel vba date for-loop


【解决方案1】:

试试:

Sub test()

    Dim arrFileNames As Variant
    Dim i As Long
    Dim strPath As String
    Dim strExt As String

    arrFileNames = Split("Book1,Book2,Book3", ",")
    strPath = "C:\Users\marios.p\Desktop\test" & "\"
    strExt = ".xlsx"

    Set fs = CreateObject("Scripting.FileSystemObject")

    For i = LBound(arrFileNames) To UBound(arrFileNames)

        Set f = fs.GetFile(strPath & arrFileNames(i) & strExt)

        If f.DateLastModified < Date Then
            MsgBox "Incorrect Date"
        End If

    Next i

End Sub

【讨论】:

    猜你喜欢
    • 2018-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-02
    • 1970-01-01
    • 2013-07-29
    • 1970-01-01
    • 2019-08-23
    相关资源
    最近更新 更多