VBA提取文件名

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Sub 提取文件名()
Dim myPath As String
Dim myFile As String
myPath = ActiveCell.FormulaR1C1 'Cells(1, 7)
n = ActiveCell.Row
myFile = Dir(myPath & "\*.*")

Do While myFile <> ""
Selection.Insert Shift:=xlDown
Cells(n, 1) = myFile
Cells(n, 2) = FileDateTime(myPath & "\" & myFile)

myFile = Dir
n = n + 1
Loop
End Sub
========================================================================
Sub 批量提取文件夹名()
Dim fs As Object
Dim myPath As String
n = ActiveCell.Row
myPath = ActiveCell.FormulaR1C1
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.getfolder(myPath)
For Each fd In f.subfolders
Cells(n, 3) = myPath &
Selection.Insert Shift:=xlDown
n = n + 1
Next
Set f = Nothing
Set fs = Nothing
End Sub


相关文档
最新文档