Application.Filesearch FileCopy

O

OP

Hi there,

I guess the subject has already been raised a thousand times, but I am
at lost wirth my macro. Of course everything worked well with Excel
2003; but as Filesearch has been removed from 2010 I can't really find a
clue to solve my problem. I looked over a couple of forums for a
filescript substitute but found nothing simple enough for me to
understand.

Here is my problem :

I have variables, (Fpath and Fname) that I run through the Filesearch
funtion. That returns me a single filename (Fil) that I use to copy to a
another folder... See the code below.

Would appreciate if anybody could help me to master this under 2010.

Thanks


With Application.FileSearch
..NewSearch
..LookIn = FPath
..SearchSubFolders = True
..Filename = fName
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
Fil = .FoundFiles(1)
Else
MsgBox "There were no files found."
Exit Sub
End If
End With
FileCopy Fil, dest + fName
 
D

Don Guillett

Hi there,

I guess the subject has already been raised a thousand times, but I am
at lost wirth my macro. Of course everything worked well with Excel
2003; but as Filesearch has been removed from 2010 I can't really find a
clue to solve my problem. I looked over a couple of forums for a
filescript substitute but found nothing simple enough for me to
understand.

Here is my problem :

I have variables, (Fpath and Fname) that I run through the Filesearch
funtion. That returns me a single filename (Fil) that I use to copy to a
another folder... See the code below.

Would appreciate if anybody could help me to master this under 2010.

Thanks

With Application.FileSearch
.NewSearch
.LookIn = FPath
.SearchSubFolders = True
.Filename = fName
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
Fil = .FoundFiles(1)
        Else
        MsgBox "There were no files found."
        Exit Sub
End If
End With
FileCopy Fil, dest + fName

Have a look in the vba help index for DIR. Post back if you still
have problems
 

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

Top