Loop through files in a folder using VBA?

后端 未结 6 2542
南笙
南笙 2020-11-21 04:40

I would like to loop through the files of a directory using vba in Excel 2010.

In the loop, I will need:

  • the filename, and
  • the date at which
6条回答
  •  佛祖请我去吃肉
    2020-11-21 05:18

    Dir takes wild cards so you could make a big difference adding the filter for test up front and avoiding testing each file

    Sub LoopThroughFiles()
        Dim StrFile As String
        StrFile = Dir("c:\testfolder\*test*")
        Do While Len(StrFile) > 0
            Debug.Print StrFile
            StrFile = Dir
        Loop
    End Sub
    

提交回复
热议问题