Macro to Place Filenames in Given Directory on WorksheetLast reviewed: March 13, 1998Article ID: Q74493 |
The information in this article applies to:
SUMMARYThe sample macros in this article place the names of all specified file types (specified by filename extension, for example .XLS) for a specified directory into a column on a worksheet.
MORE INFORMATIONBefore you run these macros, you must have the destination sheet activated. The active cell in the worksheet should be the first cell of the range that the filenames are to be placed in. To list different file types, you must modify the example macros by changing the argument in the Dir() function [FILES() function in the Microsoft Excel 4.0 example]. The Microsoft Excel 4.0 Macro Language example uses "C:\Excel\*.XLC." This returns all chart files located in the EXCEL directory. To return all Microsoft Excel add-in macros, replace "*.XLC" with "*.XLA," and so on. The specified directory can be any valid directory. Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.
Visual Basic, Applications Edition, Example
To modify the macro so that it returns the filenames in a row instead of a column, change this line
ActiveCell.Offset(1, 0).Selectto this:
ActiveCell.Offset(0, 1).Select Microsoft Excel 4.0 Macro Language
To modify the macro so that it returns the filenames in a row instead of a column, change cell A5 from R[1]C to RC[1].
REFERENCES"Function Reference," version 4.0, pages 95, 147-148, 316, 378-381 "Function Reference," version 3.0, pages 46, 75, 177, 210 "Function and Macros," version 2.1, pages 266, 278,327, 348
|
Additional query words: directories folder
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |