Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
XL: Macro to Place Filenames in Given Directory on Worksheet
Article ID: 74493 - View products that this article applies to.
This article was previously published under Q74493
The sample macros in this article place the names of all specified file types (specified by file name extension, for example .XLS) for a specified directory into a column on a worksheet.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. Before you run these macros, open a new worksheet and select the cell of the range into which you want the file names to be placed.
To list different file types, you must modify the sample macros by changing the argument in the Dir() function. To return all Microsoft Excel add-in macros, replace "*.XLS" with "*.XLA," and so on. The specified directory can be any valid directory. To search a different folder, change <ExcelFiles> to the folder containing your Excel workbook files.
To modify the macro so that it returns the file names in a row rather than in a column, change this line