Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New Function to replace With Application.FileSearch

Status
Not open for further replies.

vba317

Programmer
Mar 5, 2009
708
US
I have Windows9 with Excel 2010. I need a function to replace the Application.Filesearch Function. Some suggestions would be appreciated.

I have an example of some abbreviated code.


Code:
 Sub Openallworkbooks()

'
' Openallwkbooks1 Macro
' Macro recorded 3/31/2009
'
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False

On Error Resume Next

Set wbCodeBook = ThisWorkbook

    With Application.FileSearch
        .NewSearch
         'Change path to suit
        .LookIn = "C:\Data\Daily_A"
        
        .FileType = msoFileTypeExcelWorkbooks
        .Filename = "ETF*.xls"

            If .Execute > 0 Then 'Workbooks in folder
                For lCount = 1 To .FoundFiles.Count 'Loop through all.
                 'Open Workbook x and Set a Workbook variable to it
                 Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
                 'ActiveWindow.WindowState = xlMinimized

                
                 'DO YOUR CODE HERE

                 wbResults.Close SaveChanges:=True
                 Next lCount
            End If
    End With

    On Error GoTo 0
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    Application.EnableEvents = True


End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top