Pre 2007 macro needs VBA update for FileSearch

MikeL

Active Member
Joined
Mar 17, 2002
Messages
488
Office Version
  1. 365
Platform
  1. Windows
I used this code quite a bit to go thru all the Workbooks in a Folder and copy paste each WS in those WB to a new WB. FileSearch and FoundFiles.Count no longer work for me.

Please help.

--------------------------------------------------------
Sub Merge()


Dim i As Integer
Dim wbDest As Workbook
Dim wbSource As Workbook
Dim WS As Worksheet

Application.ScreenUpdating = False

Set wbDest = Workbooks.Add


With Application.FileSearch
.NewSearch
' Change Filepath Below To Suit
.LookIn = "T:\data"
.FileType = msoFileTypeExcelWorkbooks
.Execute

For i = 1 To .FoundFiles.Count

Set wbSource = Workbooks.Open(.FoundFiles(i))

For Each WS In wbSource.Worksheets

WS.Copy After:=wbDest.Worksheets(wbDest.Worksheets.Count)

Next WS

wbSource.Close
Next i
End With
Application.ScreenUpdating = True

End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Thanks Joe4. Its the 'do something part of that link that I am having trouble with. How will

For i = 1 To .FoundFiles.Count
Set wbSource = Workbooks.Open(.FoundFiles(i))

work now?
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

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
Back
Top