VBA 2007 How to Merge WS from Different WB in Same Folder

MikeL

Active Member
Joined
Mar 17, 2002
Messages
488
Office Version
  1. 365
Platform
  1. Windows
Hello,

Prior to XL2007 the below worked. With the now defunct FileSearch, I am unable to execute this macro.


Thanks!

-------------------------------------------------

Sub Merge_DiffXLFilesSameFolder()
'

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

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,957
Latest member
Hat4Life

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