I need help to convert this old FILESEARCH function into an alternative process that will run in Excel 2007. FileSearch was a function that was discontinued in 2007. All I need to do is point code to a folder on my C:\ and it must open each workbook, copy the first sheet into ThisWorkook and close each workbook. (GetData is another macro in the current moduule that will also run...)
I have dug around a bit using Google and the closest I have come to a solution is apparently using this object: Set FSO = CreateObject("Scripting.FileSystemobject") The sample code looked very complex and I got a few debugs in the sample code I tried to edit. So...bottom line... I need your help to create some code that will open, copy sheet and close multiple excel files in a folder i point the code to. Any help will be appreciated. Many TX
Code: Select all
Sub GetWB()
Dim myDir As String
Dim myPath As String
Dim myFileName As Variant
Dim i As Integer
myDir = ActiveWorkbook.Path ' current path
myPath = myDir & "\SurveyFiles" ' files subdir
With Application.FileSearch
.NewSearch
.LookIn = myPath
.SearchSubFolders = False
.Filename = ".xls*"
If .Execute > 0 Then
For Each myFileName In .FoundFiles
Workbooks.Open myFileName
Worksheets(1).Copy After:=ThisWorkbook.Sheets(1)
ActiveWorkbook.Close SaveChanges:=False
Call GetData
Next
End If
End With
End Sub