取文件夹中所有文件的名称,存在在excel中
程序案例:
程序案例:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
temp = ThisWorkbook.Path '设定路径
objectname = ThisWorkbook.Name '目标文件名
Set fso = CreateObject("Scripting.filesystemobject") '取目标文件
Set myf = fso.getfolder(temp)
c = 0
On Error Resume Next '有错继续
c = 1
For Each i In myf.Files '开始打开文件
If Right(i.Name, 7) <> Right(objectname, 7) Then '结果文件不统计
Cells(c, 1) = i.Name
c = c + 1
End If
Next
MsgBox "共" & c & "个文件" '提示文件个数
End Sub