Help with Application.FileSearch

gr0leau

New Member
Joined
Mar 24, 2011
Messages
3
The following works in excel macro when run in excel 2003, But not in 2007 or 2010. Can anyone help me rewrite this so it will work with 2010?

Any help would be great...

Set fs = Application.FileSearch

With fs

.LookIn = logfolder 'logfolder is a inputbox for the user to specify the 'directory where the files sit
.Filename = "*.txt"
If .Execute(SortBy:=msoSortByFileName, SortOrder:=msoSortOrderAscending) > 0 Then

For mainloop = 1 To .FoundFiles.Count

currentfile = .FoundFiles.Item(mainloop)

ParseLog (currentfile)

Next mainloop

Else
MsgBox "There were no files found - check the directory?"

End If

End With
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Code:
    Dim currentfile As String

    currentfile = Dir(logfolder [COLOR="Red"]& "\"[/COLOR] & "*.txt")
    
    If currentfile <> vbNullString Then
        Do
            ParseLog (currentfile)
            currentfile = Dir
        Loop Until currentfile = vbNullString
    Else
        MsgBox "There were no files found - check the directory?"
    End If

I don't know if your file path logfolder already includes a trailing forward slash (Red) or not.
 
Last edited:
Upvote 0
Change from previous code.

ParseLog is probably expecting the logforder path included with the file name.


Code:
    Dim currentfile As String
    
    [COLOR="Red"]logfolder = logfolder & "\"[/COLOR]
    currentfile = Dir(logfolder & "*.txt")
    
    If currentfile <> vbNullString Then
        Do
            ParseLog ([COLOR="Blue"]logfolder & [/COLOR]currentfile)
            currentfile = Dir
        Loop Until currentfile = vbNullString
    Else
        MsgBox "There were no files found - check the directory?"
    End If

I don't know if your file path logfolder already includes a trailing forward slash (Red) or not.
 
Upvote 0
Now i am getting an error when it goes to run "ParseLog (currentfile)" it gives error code 53 files not found... i feel like this is on the right track though and i appreciate the help!!!


Code:
    Dim currentfile As String

    currentfile = Dir(logfolder [COLOR=Red]& "\"[/COLOR] & "*.txt")
    
    If currentfile <> vbNullString Then
        Do
            ParseLog (currentfile)
            currentfile = Dir
        Loop Until currentfile = vbNullString
    Else
        MsgBox "There were no files found - check the directory?"
    End If
I don't know if your file path logfolder already includes a trailing forward slash (Red) or not.
 
Upvote 0
Sorry didn't read the most recent post... It now works perfectly. Thanks for the help!!!!!!!!
 
Upvote 0

Forum statistics

Threads
1,222,067
Messages
6,163,715
Members
451,854
Latest member
Tiffany Smith

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top