Getting FileName from Search

R

Rick

I am using this search:
With Application.FileSearch
.LookIn = DefaultFilePath
.TextOrProperty = FleNme
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With

How can I retrieve the file name?
I've tried everything I know, which isn't much.
 
D

Dave Peterson

Doesn't the msgbox give you the filename?
I am using this search:
With Application.FileSearch
.LookIn = DefaultFilePath
.TextOrProperty = FleNme
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With

How can I retrieve the file name?
I've tried everything I know, which isn't much.
 
D

Dave Peterson

Replace the msgbox with this if the file is closed:

name .foundfiles(i) as "C:\somenewname\here.xls"

Look at VBA's help for the Name statement for more info.
 
R

Rick

Thanks Dave, I give it a try.

Dave Peterson said:
Replace the msgbox with this if the file is closed:

name .foundfiles(i) as "C:\somenewname\here.xls"

Look at VBA's help for the Name statement for more info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top