Thread
:
FileSearch misbehaving
View Single Post
#
4
Posted to microsoft.public.excel.programming
Don Guillett
external usenet poster
Posts: 10,124
FileSearch misbehaving
What is filenameonly?
Worksheets("Sheet1").Range("A" & 11 + N).Value = .FoundFiles(N)
instead of
'Worksheets("Sheet1").Range("A" & 11 + N).Value =
(FileNameOnly(.FoundFiles(N)))
=====
You may find this easier
Sub FindFilesA()
Application.ScreenUpdating = False
Dim FN As String
Dim ThisRow As Long
Dim FileLocation As String
FileLocation = "c:\a\*.*"
FN = Dir(FileLocation)
Do Until FN = ""
ThisRow = ThisRow + 1
Cells(ThisRow, 1) = FN
FN = Dir
Loop
Application.ScreenUpdating = True
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"Robin Clay" <Robin_B DOT Clay AT virgin DOT net wrote in message
...
Greetings !
I'm sure this USED to work, but now it doesn't !
Any ideas - Please ?
----------------------------------------
' Get the folder name from Cell A4
FolderName = Range("A4").Value
'Get all the filenames
Set fs = Application.FileSearch
With fs
.LookIn = FolderName 'Path$
.FileName = "*.*"
If .Execute(SortBy:=msoSortByFileName,
SortOrder:=msoSortOrderAscending)
= 0 Then
MsgBox "There were no files found."
Else
Select Case .FoundFiles.Count
Case Is = 0
MsgBox "No files were found. Sorry!"
Case Is = 1
MsgBox Chr(34) & .FoundFiles(1) & Chr(34) & " was the only
file found."
' Process .FoundFiles(1), I
Worksheets("Sheet1").Range("A12").Value = .FoundFiles(1)
Case Else
For N = 1 To .FoundFiles.Count
BoxText$ = BoxText$ & " " & N & ". " & .FoundFiles(N) &
vbCrLf
Worksheets("Sheet1").Range("A" & 11 + N).Value =
(FileNameOnly(.FoundFiles(N)))
'Worksheets(Sheet1).Range(Chr(65 + N) & 13 + N & ":" &
Chr(65 + N) & 13 + N + 80).Font.Color = QBColor(N)
Next N
' MsgBox ("These " & .FoundFiles.Count & " files
were found:-" & vbCrLf & BoxText$)
' Process .FoundFiles(N), I
End Select
End If
End With
Range("F4") = N & "files"
-------
It runs OK, but always returns "No files were found. Sorry!"
Regards
Robin
Reply With Quote
Don Guillett
View Public Profile
Find all posts by Don Guillett