F
fredagamie
please help. I have put together a macro that will open up a folder
with my spreadsheets. The spreadsheets have a built in macro that will
copy the information i need. The next step is to place them into my
summary sheet which is where I run the original macro. The problem is
there are 4 spreadsheets in the folder, but for some reason it is only
pasting the information from workbooks 1 and 3 somehow ignoring 2 and
4. I think it is something in the loop, but can't figure out what.
any help is much appreciated.
Sub UPDATESUMMARY()
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:\Tranportation"
.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))
wbResults.RunAutoMacros xlAutoOpen
Windows("PayItem.xls").Activate
Sheets("Summary").Select
Range("A65535").End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
wbResults.Close SaveChanges:=True
Next i
End If
End With
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
with my spreadsheets. The spreadsheets have a built in macro that will
copy the information i need. The next step is to place them into my
summary sheet which is where I run the original macro. The problem is
there are 4 spreadsheets in the folder, but for some reason it is only
pasting the information from workbooks 1 and 3 somehow ignoring 2 and
4. I think it is something in the loop, but can't figure out what.
any help is much appreciated.
Sub UPDATESUMMARY()
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:\Tranportation"
.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))
wbResults.RunAutoMacros xlAutoOpen
Windows("PayItem.xls").Activate
Sheets("Summary").Select
Range("A65535").End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
wbResults.Close SaveChanges:=True
Next i
End If
End With
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub