اخي سك بابك
====
جرب هذا الكود
Sub Excel4Us_Main()
'Yahya Hussien
Dim FName As String, wbs As Workbook, FileName As String, ArrFile() As Variant, i As Integer, cl As Range
Dim Mainwb As Workbook, NewWb As Workbook
Set Mainwb = ActiveWorkbook
FName = ActiveWorkbook.Path
FileName = Dir(FName & "\*.xls*")
Do Until FileName = ""
i = i + 1
ReDim Preserve ArrFile(1 To i)
ArrFile(i) = FileName
FileName = Dir
Loop
For i = LBound(ArrFile) To UBound(ArrFile)
If ArrFile(i) <> Mainwb.Name Then
Workbooks.Open FName & "\" & ArrFile(i)
Set NewWb = ActiveWorkbook
NewWb.Sheets("التقدير").Range("A2:D1000").ClearContents
For Each cl In Mainwb.Sheets("Class 1").Range("G3:G10")
If cl.Value = NewWb.Sheets("التقدير").Range("J1") Then
LR = NewWb.Sheets("التقدير").Range("A" & Rows.Count).End(xlUp).Row + 1
NewWb.Sheets("التقدير").Range("A" & LR).Value = Mainwb.Sheets("Class 1").Cells(cl.Row, 1).Value
NewWb.Sheets("التقدير").Range("B" & LR).Value = Mainwb.Sheets("Class 1").Cells(cl.Row, 6).Value
NewWb.Sheets("التقدير").Range("C" & LR).Value = Mainwb.Sheets("Class 1").Cells(cl.Row, 7).Value
NewWb.Sheets("التقدير").Range("D" & LR).Value = Mainwb.Sheets("Class 1").Cells(cl.Row, 8).Value
End If
Next
'************************************************************************************************
For Each cl In Mainwb.Sheets("Class 2").Range("G3:G10")
If cl.Value = NewWb.Sheets("التقدير").Range("J1") Then
LR = NewWb.Sheets("التقدير").Range("A" & Rows.Count).End(xlUp).Row + 1
NewWb.Sheets("التقدير").Range("A" & LR).Value = Mainwb.Sheets("Class 2").Cells(cl.Row, 1).Value
NewWb.Sheets("التقدير").Range("B" & LR).Value = Mainwb.Sheets("Class 2").Cells(cl.Row, 6).Value
NewWb.Sheets("التقدير").Range("C" & LR).Value = Mainwb.Sheets("Class 2").Cells(cl.Row, 7).Value
NewWb.Sheets("التقدير").Range("D" & LR).Value = Mainwb.Sheets("Class 2").Cells(cl.Row, 8).Value
End If
Next
NewWb.Save
NewWb.Close False
End If
1 Next i
End Sub
ضعه في موديول
وضع هذا في حدث ThisWorkeBook
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call Excel4Us_Main
End Sub