Sub 提取文件名称()
Cells.Clear
Dim str$, fso, file, i&
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show = -1 Then
str = .SelectedItems(1)
If Right(str, 1) <> "\" Then
str = str & "\"
End If
End If
End With
i = 1
Set fso = CreateObject("scripting.filesystemobject")
For Each file In fso.getfolder(str).Files
Cells(i, 1) = file.Name
i = i + 1
Next
End Sub
给你个附件
点击按钮
输入文件夹路径
点击确定
只能在excel2007及以上版本使用