VBA Site contains VBA code to create macros in WORD EXCEL ACCESS OUTLOOK

 

Comparing two files

 

Sub Filestest()

Application.ScreenUpdating = False

Dim ob As Object, files As Object, file As Object

Dim FolderName As String

With Application.FileDialog(msoFileDialogFilePicker)

.AllowMultiSelect = False

.Show

oryg = .SelectedItems(1)

flnm = Dir(oryg)

End With

Workbooks.Open oryg

Workbooks(flnm).Activate

Row = ActiveWorkbook.ActiveSheet.UsedRange.Rows.Count

Col = ActiveWorkbook.ActiveSheet.UsedRange.Columns.Count

Dim a() As Variant

ReDim Preserve a(Row - 1, Col - 1)

For i = 0 To Row - 1

For j = 0 To Col - 1

a(i, j) = ActiveWorkbook.ActiveSheet.Cells(i + 1, j + 1)

Next j

Next i

Dim ob1 As Object, files1 As Object, file1 As Object

Dim FolderName1 As String

With Application.FileDialog(msoFileDialogFilePicker)

.AllowMultiSelect = False

.Show

oryg1 = .SelectedItems(1)

flnm1 = Dir(oryg1)

End With

Workbooks.Open oryg1

Workbooks(flnm1).Activate

Row1 = ActiveWorkbook.ActiveSheet.UsedRange.Rows.Count

Col1 = ActiveWorkbook.ActiveSheet.UsedRange.Columns.Count

Dim b() As Variant

ReDim Preserve b(Row1 - 1, Col1 - 1)

For i = 0 To Row1 - 1

For j = 0 To Col1 - 1

b(i, j) = ActiveWorkbook.ActiveSheet.Cells(i + 1, j + 1)

Next j

Next i

MsgBox "You compare files: " & vbNewLine & flnm & vbNewLine & flnm1

For i = 0 To Row - 1

For j = 0 To Col - 1

If a(i, j) <> b(i, j) Then

MsgBox "For example in the file : " & flnm & ": row# " & i + 1 & " & column# " & j + 1 & " is value: " & a(i, j) & vbNewLine & _

"and in the file: " & flnm1 & ": row# " & i + 1 & " & column# " & j + 1 & " is value: " & b(i, j), , flmn

GoTo ercheck

Else

End If

Next j

Next i

For i = 0 To Row1 - 1

For j = 0 To Col1 - 1

If a(i, j) <> b(i, j) Then

MsgBox "For example in the file : " & flnm & ": row# " & i + 1 & "& column# " & j + 1 & " is value: " & a(i, j) & vbNewLine & _

"and in the file: " & flnm1 & ": row# " & i + 1 & "& column# " & j + 1 & " is value: " & b(i, j), , flmn1

GoTo ercheck

Else

End If

Next j

Next i

GoTo okcheck

ercheck:

MsgBox "Files are not identical!", vbExclamation, "Files' test result"

GoTo endofcheck

okcheck:

MsgBox "Files are identical!", vbInformation, "Files' test result"

endofcheck:

Erase a

Erase b

Application.ScreenUpdating = True

End Sub



Dodaj komentarz






Dodaj

© 2013-2024 PRV.pl
Strona została stworzona kreatorem stron w serwisie PRV.pl