Loop through files in a folder using VBA?

后端 未结 6 2315
南笙
南笙 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:10

    Dir function loses focus easily when I handle and process files from other folders.

    I've gotten better results with the component FileSystemObject.

    Full example is given here:

    http://www.xl-central.com/list-files-fso.html

    Don't forget to set a reference in the Visual Basic Editor to Microsoft Scripting Runtime (by using Tools > References)

    Give it a try!

提交回复
热议问题