Thursday, March 25, 2010

Search file from a specific folder

Private Sub SearchFile()

Set fs = Application.FileSearch
With fs
.LookIn = Environ("userprofile") & Application.PathSeparator & "Desktop" & Application.PathSeparator & "Source File" & Application.PathSeparator
.FileType = msoFileTypeExcelWorkbooks
If .Execute > 0 Then
Sheets("FilePath").Select
For i = 1 To .FoundFiles.Count
If (InStr(1, .FoundFiles(i), "Template") = 0) Then
Range("A" & (i + 1)).Value = .FoundFiles(i)

End If
Next i
Else
'MsgBox "There were no Binder files found."
End If
End With

Columns("A:A").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Delete Shift:=xlUp
Selection.End(xlUp).Select

End Sub

No comments:

Post a Comment