Loop through files in a folder using VBA?

后端 未结 6 2309
南笙
南笙 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-21 04:59

    Dir seems to be very fast.

    Sub LoopThroughFiles()
        Dim MyObj As Object, MySource As Object, file As Variant
       file = Dir("c:\testfolder\")
       While (file <> "")
          If InStr(file, "test") > 0 Then
             MsgBox "found " & file
             Exit Sub
          End If
         file = Dir
      Wend
    End Sub
    

提交回复
热议问题