The thing is, the Master Template has a macro which is basically used to open up all Excel files in a specified folder :
Sub ProcessAll()
Dim Wb As Workbook, sFile As String, sPath As String
Dim itm As Variant
Dim strFileNames As String
sPath = "C:\Test1\"
' Retrieve the current xl files in directory
sFile = Dir("C:\Test1\" & "*.xls")
Do While sFile <> ""
strFileNames = strFileNames & "," & sFile
sFile = Dir()
Loop
' Open each file found
For Each itm In Split(strFileNames, ",")
If itm <> "" Then
Set Wb = Workbooks.Open(sPath & itm)
Call CallData 'this runs my macro from above
Wb.Close True
End If
Next itm
End Sub
And so the CallData macro should only be about copying and pasting, a bit like this I suppose:
Sub CallData()
'
' CallData Macro
'
'
For Each cell In Sheets("Ignore-this-sheet").UsedRange
If cell.Row <> r Then
If cell.Value <> vbNullString Or cell.Value <> 0 Then
cell.EntireRow.Copy
Windows("Master Template ex.xls").Activate
If Range("A2").Value <> vbNullString Then
Range("A1").End(xlDown).Offset(1, 0).PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Else
Range("A2").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
End If
Windows(survey).Activate
r = cell.Row
End If
End If
Next
Application.ScreenUpdating = True
End Sub
But the problem with the above CallData macro code is the
Windows(survey).Activate
r = cell.Row
End If
bit I suppose, which tells it to go back to the open survey window. Ideally, as in the ProcessAll macro, the xls files in a single folder should be opened, the correct rows copied over, and then the files closed. All done one by one.
Bookmarks