Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COPY only file names into excel

Status
Not open for further replies.

tizzodizzo

Programmer
Oct 21, 2008
9
US
I am trying to copy just the names of a file from a directory and patse it into different cell within excel. I don't need anything from with-in the file. I just need the name of the file. Can anyone Help?
 
Hi,

Check out the FileSystemObject

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 

... or Dir Function
Returns a String representing the [blue]name of a file[/blue], directory, or folder that matches a specified pattern or file attribute, or the volume label of a drive.

Syntax

Dir[(pathname[, attributes])]

Have fun.

---- Andy
 
Hi tizzodizzo,

You could use something like:
Code:
Public Sub ListAllFiles()
Dim FName As Variant
Dim i As Integer
i = 0
FName = Dir("C:\My Documents\*.xls", vbNormal)
While FName <> ""
  i = i + 1
  ActiveSheet.Cells(i, 1).Value = FName
  FName = Dir()
Wend
End Sub
Note that, as coded, the macro only lists xls files in the nominated folder. To get a different file type, change the 'xls' in the code to suit (use '*.*' for all files).

Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top