打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
28,2007版FSO方法搜索文件夹文件

'282007FSO方法搜索文件夹文件

'2014-12-17

'http://www.excelpx.com/thread-336169-1-1.html

Sub lqxs()

    Dim Fso, Folder,myPath$, hz$, sh As Worksheet

    Dim i&, nm1$, Files,File, r%, c%

   Application.ScreenUpdating = False

    Sheet1.Activate

    cwells.ClearContents hz= "xls"

    [a1].Resize(1, 3) =Array("文件夹","工作簿名","工作表名")

    r = 1

    myPath =ThisWorkbook.PATH & "\"

    Set Fso =CreateObject("Scripting.FileSystemObject")

    For Each myfol InFso.getfolder(myPath).SubFolders

       Set Files = myfol.Files

       If Files.Count <> 0 Then

           For Each File In Files

               If InStr(File, hz) Then

                   r = r + 1

                   Cells(r, 1) = myfol.Name

                   nm1 = Mid(File, InStrRev(File, "\") + 1)

                   Cells(r, 2) = nm1: c = 2

                   With GetObject(File)

                       For Each sh In .Sheets

                           c = c + 1

                           Cells(r, c) = sh.Name

                       Next

                       .Close False

                   End With

               End If

           Next

       End If

    Next

    Set Folder =Fso.getfolder(myPath)

    Cells(r + 1, 1) =Folder.Name

    Set Files = Folder.Files

    If Files.Count <>0 Then

       For Each File In Files

           If InStr(File, hz) Then

               r = r + 1

               nm1 = Mid(File, InStrRev(File, "\") + 1)

               Cells(r, 2) = nm1: c = 2

               With GetObject(File)

                   For Each sh In .Sheets

                       c = c + 1

                       Cells(r, c) = sh.Name

                   Next

                   .Close False

               End With

           End If

       Next

    End If

End Sub

'http://club.excelhome.net/thread-883319-1-1.html

'2012-6-20

Sub yy()

    Dim Fso, Folder,myPath$, hz$

    Dim i&, nm1$, Files,File, r%, Arr1()

   Application.ScreenUpdating = False

    hz = "txt"

    r = 0

    myPath =ThisWorkbook.PATH & "\数据\"

    Set Fso =CreateObject("Scripting.FileSystemObject")

    Set Folder =Fso.getfolder(myPath)

    Set Files = Folder.Files

    If Files.Count <>0 Then

       For Each File In Files

           If InStr(File, hz) Then

               r = r + 1

               ReDim Preserve Arr1(1 To r)

               nm1 = Mid(File, InStrRev(File, "\") + 1)

               Arr1(r) = nm1

           End If

       Next

    End If

    WithSheet1.[a1].Validation

        .Delete

       .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _

       Operator:=xlBetween, Formula1:=Join(Arr1, ",")

    End With

End Sub

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
三、文件系统对象FSO操作目录与文件
【烟花原创】VBA零基础之第208篇FSO对象(7)
如何遍历子文件夹,找到所需的文件,并拷贝到指定目录呢?
Excel VBA 之 按需求移动、复制文件
遍历文件夹(含子文件夹)方法:FSO 递归方法实现各种指定搜寻的完整代码
教你快速删除电脑久存的无用文件夹 为电脑腾出空间
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服