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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copying file names into a spreadsheet 1

Status
Not open for further replies.

scottie1

Programmer
Dec 12, 2003
50
GB
Hi All

Can anybody tell me how to copy file names from a folder list in windows explorer into an excel spreadsheet all in one go. Thats if there is a way. It's so when I save sheets in a workbook I save them as the name of the worksheet but sometimes people writing sheet names put spaces at the end, so if you go and look for the file afterwards you can't find it.

Good Luck
 
Something like this should help:

Code:
Directory = "C:\Windows\"
x=1
Cells(x,1) = "Filename"
x=x+1
fil=Dir(Directory,7)
cells(x,1)=fil
do while fil<>""
  fil=Dir
  If fil<>"" then
    x=x+1
    Cells(x,1)=fil
  End if
Loop
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top