+ Reply to Thread
Results 1 to 3 of 3

File Search

  1. #1
    mburkett
    Guest

    File Search

    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


  2. #2
    Bernie Deitrick
    Guest

    Re: File Search

    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

    "mburkett" <[email protected]> wrote in message
    news:[email protected]...
    > 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
    >




  3. #3
    mburkett
    Guest

    Re: File Search

    This worked. Thank you for your timely and accurate response!


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1