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
如何自动执行此操作,以便我不必在每行的代码中写一行?
答案 0 :(得分:1)
您只需要实现一个基本循环
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