Cutting down returned results???
Posted by RoB on November 11, 2001 2:38 AM
I have a macro that uses the data in cell A1 to do a seach in the directory "e:\Macros", then it lists the files returned starting in cell A2. I have 2 questions:
1. currently, the returned results show as a full path ie: "e:\Macros\test.xls". I would like to have it just display the file (without extension) which would be "test" in this case. How would i go about "cutting" the result down to what i want? Please remember there are also sometimes more than one directory as the search looks in subdirectories. so a possible return could be "e:\Macros\subdir\test2.xls"
2. Not only would i like only to display ONLY the file name, but i would like to turn it into a link to the file. Can someone help me with this??
Heres the code if you need it:
Sub FileSearch()
Dim Criteria As String
Criteria = Range("A1")
With Application.FileSearch
.LookIn = "e:\Macros"
.SearchSubFolders = True
.Filename = Criteria & "*"
.FileType = msoFileTypeExcelWorkbooks
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
Cells(i + 1, 1) = .FoundFiles(i)
'MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub