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
 

Some videos you may like

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

AlphaFrog

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

Watch MrExcel Video

Forum statistics

Threads
1,123,270
Messages
5,600,635
Members
414,398
Latest member
dhune

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