Each day I receive 5 excel workbooks containing pivot tables.
I need to extract the underlying data for importing into Access, so
I created the following 2 procs.
Proc1:
Sub XtractFails()
Dim Wb As Workbook
For Each Wb In Workbooks
Call SvFlz
Next Wb
Application.StatusBar = ""
End Sub
Proc2:
Sub SvFlz()
'
Application.DisplayAlerts = False
Dim strFName, strSuffix As String
strFName = Left(ActiveWorkbook.Name, InStr
(ActiveWorkbook.Name, " ") - 1)
strSuffix = ".xls"
Sheets("Nostro By Counterparty").Select
ActiveCell.SpecialCells(xlLastCell).Select
If strFName = "NYAF" Then
ActiveSheet.PivotTables("PivotTable6").PivotSelect "'Grand
Total'", xlDataOnly
Selection.ShowDetail = True
Else
ActiveSheet.PivotTables("PivotTable4").PivotSelect "'Grand
Total'", xlDataOnly
Selection.ShowDetail = True
End If
ChDir "MyPath"
ActiveWorkbook.SaveAs Filename:="MyPath" & strFName & strSuffix,
_
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWindow.Close
Application.DisplayAlerts = True
Application.StatusBar = strFName & " Completed!"
End Sub
The problem is that the ForEach loop stops after the first 2
workbooks. I call it a second time and it does the remaining 3.
The order of the workbooks does not seem to make a difference, but
no matter what I've tried I cannot get this to process all 5.
I've been looking at it for way too long, perhaps another set of
eyes can spot what is breaking the loop.