Dim FSO As New FileSystemObject Dim myFolder As String Dim Fld As Folder Dim Fli As File Dim i As Integer
myFolder = "C:\Documents and Settings\chaoliang_lv\Desktop\myfolder" Set Fld = FSO.GetFolder(myFolder)
If Fld.Files.Count = Application.WorksheetFunction.CountA(Range("A:A")) - 1 Then MsgBox "Already the lastest!" Exit Sub End If
Sheet1.Range("A1").CurrentRegion.Offset(1, 0).Clear i = 2 For Each Fli In Fld.Files Range("A" & i).Value = FSO.GetBaseName(Fli) Range("B" & i).Value = Fli.DateLastModified i = i + 1 Next Fli MsgBox "Updated!"
本例假设文件另存为:C:\aaa.xls,你可以自行修改 请在ThisWorkBook对象中输入如下代码: Private Sub Workbook_BeforeClose(Cancel As Boolean) ActiveWorkbook.SaveAs Filename:="C:\aaa.xls", _ FileFormat:=xlNormal, Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False End Sub