View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
KL KL is offline
external usenet poster
 
Posts: 201
Default Sub "Fill cells using file name" ()

Hi,

You may try this code (I haven't tested it though). The function split will
fail in XL97 and below.

Sub ListFiles()
Dim Ruta As String, x As Integer, n As Variant
Ruta = "C:\temp\"
Set fs = Application.FileSearch
Application.ScreenUpdating = False
On Error Resume Next
With fs
.LookIn = Ruta
.SearchSubFolders = False
.Filetype = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
For i = 1 To .FoundFiles.Count
Workbooks.Open .FoundFiles(i)
n = Split(Trim(Replace(Dir(.FoundFiles(i)), ".xls", "")), "
")
ActiveWorkbook.Sheets("ledger").Range("A1:A2").Val ue = _
WorksheetFunction.Transpose(n)
Next i
End If
End With
Application.ScreenUpdating = True
End Sub

Regards,
KL
"Karthik Bhat - Bangalore" wrote in message
oups.com...
Hi

I have a set of excel files (about 100) stored in a specified folder
(say "c:\temp"). All the file names have two parts; the first part
is name of a person and seconds his location, separated by a
'space'. Example (David Paris.xls, Tim NY.xls ... etc) and all
files have similar structure.

What I want is a code that will open each of these files go to a
worksheet named 'ledger' and put the name of the person in cell A1
and location in Cell A2 (both from file name).The code should do this
until it finishes all the files in the folder.

Thanks for taking time to help me

Karthik Bhat
Bangalore