查看: 24  |  回复: 0
  VBA代码 folderlist文件夹列表
楼主
发表于 2025年3月18日 14:17
Private Function f_FolderList(folderspec, Optional pstr = "*")
    '遍历某文件夹下的文件夹,pstr用通配符指定筛选条件
    Dim fs, f, f1, fc, i, arr
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(folderspec)
    Set fc = f.subfolders
    ReDim arr(1 To fc.Count)
    For Each f1 In fc
        If f1.Name Like pstr Then
            i = i + 1
            arr(i) = f1.Name
        End If
    Next
    ReDim Preserve arr(1 To i)
    f_FolderList = arr
End Function


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2025 MaNongKu.com