在这些档案的文件夹(确保这个文件夹下只有你说的那些数字的文件,最好不要有别的文件,而且数字的位数最好要相等,否则可能会计算出很多不可预测的结果)
下新建一个excel文件
然后按ALT+F11
双击右边中部的:"Thisworkbook"
再把以下内容粘贴进去。
保存,运行(按F5)即可。
返回Excel文件即可以看到相关信息。D列就是缺少的文件名
Sub loadfile()
Dim file As String
Dim i As Integer
Dim r As Integer
Dim temp As Long
Dim lack As Integer
Worksheets("sheet1").Columns("A:g").ClearContents
file = Dir(ActiveWorkbook.Path & "\", 7)
r = 1
Do While file <> ""
file = Left(file, InStrRev(file, ".") - 1) '去扩展名
If file <> ActiveWorkbook.Name And VBA.IsNumeric(file) Then
Cells(r, 1) = r
Cells(r, 2) = file
r = r + 1
End If
file = Dir()
Loop
For i = 1 To r
Cells(i, 3) = Cells(i, 2)
Next i
Columns("C:C").Sort Key1:=Range("C1"), Order1:=xlAscending
lack = 0
temp = Cells(1, 3)
i = 2
Do While i <= r
nexttemp:
temp = temp + 1
If temp <> Cells(i, 3) Then
If Left(temp, 4) = Left(Cells(i, 3), 4) Then
lack = lack + 1
Cells(lack, 4) = temp
GoTo nexttemp
Else
temp = Cells(i, 3)
End If
End If
i = i + 1
Loop
End Sub