
Originally Posted by
EsKay!
I will appreciate if you could answer the following questions:
1. What does "InvoiceTest" in Workbooks("InvoiceTest") stand for? Is it the file name?
2. What should I type in = Range ("M3") if the range in each of the worksheets is A1 to HC1150?
Please place this code in a workbook "InvoiceTest"(for this example)that is not in the folder to extract the info,
This example searches a folder called C:\Invoices\ you will have to change it for the folder you require.
Check to make sure the sheet names are correct as well...
Sub GetNewData()
Dim i As Integer
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:\Invoices\"
.FileType = msoFileTypeExcelWorkbooks
If .Execute > 0 Then 'Workbooks in folder
For i = 1 To .FoundFiles.Count 'Loop through all
'Open Workbook x and Set a Workbook variable to it
Set wbResults = Workbooks.Open(.FoundFiles(i))
ActiveSheet.Range("A1:HC1150").Copy _
Destination:=Workbooks("InvoiceTest").Sheets("Sheet1").Range("A65536").End(xlUp).Offset(1, 0)
ActiveWorkbook.Close savechanges:=False
Next i
End If
End With
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
Bookmarks