尝试使用数组检索路径中的最后一个文件夹,它正在运行,但在脚本执行结束时返回运行时错误9,下标超出范围。 `
Dim a As Variant
i = 5
For n = LBound(files) To UBound(files)
a = Split(files(n), "\")
FnameInLoop = a(UBound(a) - 1)
Cells(i, 1).Value = FnameInLoop
i = i + 1
Next n`
@MathieuGuindon解决了,谢谢你的输入产生了成功的结果,只是添加了检查值是否为null,如下:
`' extract last folder in path
Dim a As Variant
i = 5
For n = LBound(files) To UBound(files)
a = Split(files(n), "\")
If Not Fnameinloop = "" Then
Fnameinloop = a(UBound(a) - 1)
Cells(i, 1).Value = Fnameinloop
End If
i = i + 1
Next n
`