How do I copy multiple file names?

Copy file names tosheet

  • I want to "import" a list of all file names with a .h extension into mysheet. Thefile and the .h files will reside in the same directory. So if I have the file names: test.h good.h min.h I should get these mames in the cells B2 though B4 Thanks for your help Thomas

  • Answer:

    To accomplish, you must be familiar with Visual Basic for Applications coding (vba, or "macros"). 'From within any module in the Visual Basic Editor, choose from the main 'menu Tools, References and make sure that "Microsoft Scripting Runtime" is 'checked. Then run this sub to list all files in folder C:\TEMP with a name 'that ends in ".h": Sub fileList() Dim fso As Scripting.FileSystemObject Dim fld As Scripting.Folder Dim file As Scripting.file Dim listHere As Range Set listHere = ThisWorkbook.Sheets("sheet1").Range("b2") Set fso = New FileSystemObject Set fld = fso.GetFolder("C:\TEMP\") For Each file In fld.Files If Right(file.Name, 2) = ".h" Then listHere.Value = file.Name Set listHere = listHere.Offset(1) End If Next file End Sub

Miningco.com Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.