File Search

M

mburkett

I am using the code below to find text files for importing in to Excel.
I am getting the an error message "Run-Time error '5': Invalid
procedure call or argument." The strange part is that I copied this
code exactly from another workbook and it work beautifully. Any idea
why it would work on one workbook and not another? It bombs out on the
file .FileType = msoFileTypeAllFiles.

Sheets("Dialog Output").Select
Range("g3").Select
act = Selection.Value
Range("g4").Select
mgr = Selection.Value
Range("g5").Select
stdt = Selection.Value
Range("g6").Select
enddt = Selection.Value
With Application.FileSearch
.NewSearch
.LookIn = "F:\MAIN\Michael\EXCEL\Trading\Blk Files\"
.FileType = msoFileTypeAllFiles
.SearchSubFolders = False
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
If .FoundFiles(i) Like "*" + act + "*.txt" And .FoundFiles(i)
Like "*" + mgr + "*.txt" Then
If FileDateTime(.FoundFiles(i)) >= stdt And
FileDateTime(.FoundFiles(i)) <= enddt Then

Thanks - Michael
 
B

Bernie Deitrick

Michael,

You need to set a reference to the MS office object library - in the VBE,
use Tools | References... and find it in the list, and check the box next to
it.

HTH,
Bernie
MS Excel MVP
 

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