Hi Nate,
I tried the code used here but got stock on the
Const searchTerm As String = "projects"
because is a set term. I am trying to use a "number" from a UserForm Text box.
It works on the excel 2003 but not on the 2007
Please! I need your help.
Here is my code:
========
Sub FindThatFile()
Dim strMyString As String
strMyString = UserForm30.TextBox1.Value
With Application.FileSearch
.Filename = strMyString
.LookIn = "
\\Ddnydc3\drafting"
.FileType = msoFileTypeAllFiles
.SearchSubFolders = True
.MatchTextExactly = True
.Execute
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
UserForm31.TextBox1.Text = .FoundFiles(i)
UserForm31.Show
Next i
UserForm30.TextBox1.AutoTab = True
UserForm30.TextBox1.SetFocus
UserForm30.TextBox1.Value = "00"
Else
MsgBox "That Part Number has NOT been scanned or it Does NOT Exist", _
vbExclamation + vbOKOnly, _
"Sorry!"
UserForm30.TextBox1.AutoTab = True
UserForm30.TextBox1.SetFocus
End If
End With
End Sub
=============
Well, first you start out with the recursive routine to generate your filelist.
Here's one take on what this might look like:
Code:
Sub foobar()
Dim fso As Object
Dim strName As String
Dim strArr(1 To 65536, 1 To 1) As String, i As Long
Const strDir As String = "C:\temp"
Const searchTerm As String = "projects"
Let strName = Dir$(strDir & "\*" & searchTerm & "*.xls")
Do While strName <> vbNullString
Let i = i + 1
Let strArr(i, 1) = strDir & "\" & strName
Let strName = Dir$()
Loop
Set fso = CreateObject("Scripting.FileSystemObject")
Call recurseSubFolders(fso.GetFolder(strDir), strArr(), i, searchTerm)
Set fso = Nothing
If i > 0 Then
Range("A1").Resize(i).Value = strArr
End If
End Sub
Private Sub recurseSubFolders(ByRef Folder As Object, _
ByRef strArr() As String, _
ByRef i As Long, _
ByRef searchTerm As String)
Dim SubFolder As Object
Dim strName As String
For Each SubFolder In Folder.SubFolders
Let strName = Dir$(SubFolder.Path & "\*" & searchTerm & "*.xls")
Do While strName <> vbNullString
Let i = i + 1
Let strArr(i, 1) = SubFolder.Path & "\" & strName
Let strName = Dir$()
Loop
Call recurseSubFolders(SubFolder, strArr(), i, searchTerm)
Next
End Sub
Note though, Indirect() does not work on closed files.