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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,450
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:

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,450
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.
 

gr0leau

New Member
Joined
Mar 24, 2011
Messages
3
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.
 

gr0leau

New Member
Joined
Mar 24, 2011
Messages
3
Sorry didn't read the most recent post... It now works perfectly. Thanks for the help!!!!!!!!
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,987
Messages
5,834,720
Members
430,313
Latest member
smartykatwinks

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
Top