View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
flummi
 
Posts: n/a
Default excel cell lookup file on harddrive

Here's a VBA procedure.

Try it and if okay modify it to meet your needs. Create a command
button on your worksheet, right click it in design mode, select 'view
code' and copy the code below between private sub and end sub.

The names of the manufacturers you oare looking for is supposed to be
in A1:?1 (I have provided for 50 cells). Empty name cells are ignored.
If a file is found, it says "OK" in A2 .... and it lists the files from
A4 down.

With Application.FileSearch
NumNames = 50
Path = "c:\" 'your path here
For t = 1 To NumNames
If Worksheets("Sheet1").Cells(1, t).Value < "" Then
.NewSearch
.LookIn = Path
.SearchSubFolders = False 'if you want to search
subfolders, set to true
.Filename = Worksheets("Sheet1").Cells(1, t)
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
If .Execute() 0 Then
Worksheets("Sheet1").Cells(2, t).Value = "OK"
For i = 1 To .FoundFiles.Count
Worksheets("Sheet1").Cells(i + 3, t).Value =
..FoundFiles(i)
Next i
Else
Worksheets("Sheet1").Cells(2, t).Value = "Not found"
End If
End If
Next t
End With

Hope it helps.

Hans