代码之家  ›  专栏  ›  技术社区  ›  TobiasH

填充B列中最后修改的文件列表(A)的时间戳

  •  0
  • TobiasH  · 技术社区  · 7 年前

    A列包含没有扩展名的文件名,我希望B列显示上次修改的时间和日期。

    Sub Workbook_Open()
    Dim Path As String
    Path = ThisWorkbook.Sheets("E").Range("B14")
    Range("B4").Value = FileDateTime(Path & ThisWorkbook.Sheets("Projekterfassung_Monitoring").Range("A4") & ".xlsx")
    Range("B5").Value = FileDateTime(Path & ThisWorkbook.Sheets("Projekterfassung_Monitoring").Range("A5") & ".xlsx")
    Range("B6").Value = FileDateTime(Path & ThisWorkbook.Sheets("Projekterfassung_Monitoring").Range("A6") & ".xlsx")
    Range("B7").Value = FileDateTime(Path & ThisWorkbook.Sheets("Projekterfassung_Monitoring").Range("A7") & ".xlsx")
    (...)
    End Sub
    

    1 回复  |  直到 6 年前
        1
  •  1
  •   Tom    7 年前

    您只需要实现一个基本循环

    Sub Workbook_Open()
        Dim Path As String
        Dim i As Long
        Path = ThisWorkbook.Sheets("E").Range("B14")
    
        With ThisWorkbook.Sheets("Projekterfassung_Monitoring")
            For i = 4 To .Cells(.Rows.Count, 1).End(xlUp).Row
                .Range("B" & i).Value = FileDateTime(Path & .Range("A" & i) & ".xlsx")
            Next i
        End With
    End Sub