|
请教老师:
下例中,如果待改名的文件固定保存在指定目录如何实现,意思是不用每次去选择目录
----------------------
Dim filePath As Variant '定义filepath为变量
Dim obj As Object '定义obj为变量对象
Dim fld, ff, gg '定义fld,ff,gg为变量
Sub 提取文件列表()
Range("A2:A1000").ClearContents '清空A2:C1000列
'待改名字图片保存路径是固定的:"E:\待处理图片"
On Error Resume Next
Dim shell As Variant
Set shell = CreateObject("Shell.Application")
Set filePath = shell.BrowseForFolder(&O0, "选择文件夹", &H1 + &H10, "") '获取文件夹路径地址
Set shell = Nothing
If filePath Is Nothing Then '检测是否获得有效路径,如取消直接跳出程序
Exit Sub
Else
gg = filePath.Items.Item.path
End If
Set obj = CreateObject("Scripting.FileSystemObject") '定义变量
Set fld = obj.getfolder(gg) '获取路径
For Each ff In fld.Files '遍历文件夹里文件
m = m + 1
Cells(m + 1, 1) = ff.Name
Next
End Sub |
|