Hi Guys
I no know why shows this error
"Sorry We Could Not Find FILE1.xlsx. Is it possible it was moved, renamed or deleted"?
in this line
Set Workbook1 = Workbooks.Open(File1)
despite of I'm really sure this file is existed and matched with name and I check it by another macro and open it without any problem . I no know why show this error!!
Sub Compare_Two_Files()
Dim Workbook1 As Workbook
Dim Workbook2 As Workbook
Dim Rng1 As Range
Dim Rng2 As Range
Dim i As Integer, j As Integer
File1 = "File1.xlsx"
File2 = "File2.xlsx"
File1_Sheet = "Sheet1"
File2_Sheet = "Sheet1"
Set Workbook1 = Workbooks.Open(File1)
Set Workbook2 = Workbooks.Open(File2)
Set Rng1 = Workbook1.Worksheets(File1_Sheet).UsedRange
Set Rng2 = Workbook2.Worksheets(File2_Sheet).UsedRange
Count = 1
For i = 1 To Rng1.Rows.Count
For j = 1 To Rng1.Columns.Count
If Rng1.Cells(i, j) <> Rng2.Cells(i, j) Then
For k = 1 To Rng1.Rows.Count
Sheet1.Cells(Count, k) = Rng2.Cells(i, k)
Next k
Count = Count + 1
Exit For
End If
Next j
Next i
Workbook1.Close
Workbook2.Close
Set Rng1 = Nothing
Set Rng2 = Nothing
Set Workbook1 = Nothing
Set Workbook2 = Nothing
End Sub
anybody can guid me what's my mistake ,please?