Sub SearchForAccount()
Dim i As Long
Dim sStr As String
Dim MyVar As String
Dim FileList() As String
ReDim FileList(0 To 0)
sStr = "C:\"
With Application.FileSearch
.NewSearch
.LookIn = sStr
.SearchSubFolders = True
.FileName = "account.xls"
.FileType = msoFileTypeExcelWorkbooks
If .Execute() > 0 Then
If i = 1 Then
MyVar = .FoundFiles(i)
Else
ReDim FileList(1 To .FoundFiles.Count)
For i = 1 To .FoundFiles.Count
FileList(i) = .FoundFiles(i)
Next i
End If
Else
MsgBox "There were no files found."
End If
End With
If LBound(FileList) = 1 Then
For i = LBound(FileList) To UBound(FileList)
ActiveSheet.Cells(i, 1).Value = FileList(i)
Next
Else
Activesheets.Cells(1, 1).Value = MyVar
End If
End Sub
The results will contain the fully qualified filename (path included).
note that this can pick up myaccount.xls as well, so once the list is
returned, you need to examine each file name and make sure it is the file
you are interested in - but it looks like you will need to do that anyway to
account for multiple files.
--
Regards,
Tom Ogilvy
"John Baker" <Baker.JH@Verizon.net> wrote in message
news:37d2u0hpk02kf1valitg96l3l60ki1f74t@4ax.com...
> Lonnie:
>
> Thanks very much. I know that I can tweak it so that when more than one
file is found I
> tell the user to select manually, but I am not quite certain how to grab
the path for a
> file when the file count is 1. I would appreciate a suggestion as to the
command. ONce I
> grab it I can embed it in the originating spreadsheet or set it up as a
variable, and the
> world is my oyster!
>
> Thanks again
>
> John Baker
>
> "Lonnie M." <lonnie_r_m@hotmail.com> wrote:
>
> >Hi John,
> >Tom Ogilvy posted an answer to a similar question:
> >
>
>http://groups-beta.google.com/group/...ogramming/brow
se_frm/thread/d6f2fcc219e70930#1f841e64d2fa3e7e
> >I think you could probably tweak this for your needs.
> >HTH--Lonnie M.
>
Bookmarks