1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| Option Explicit
Dim objExcel, Sheet1, Sheet2, X, ColsCount, iRow, tmpText, Delim, fso, RowsCount
'On modifiera les chemins selon le besoin
Delim = "\*/"
Sheet1 = "C:\Fich1.xls"
Sheet2 = "C:\Fich2.xls"
Set fso = CreateObject("Scripting.FileSystemObject")
WriteToTextFile Sheet1, "C:\Fich1.txt"
WriteToTextFile Sheet2, "C:\Fich2.txt"
Wscript.Sleep 2000
TestFiles "C:\Fich1.txt", "C:\Fich2.txt"
'========================================
Sub WriteToTextFile(SfileExcel, txtFile)
Dim objfich
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
objExcel.DisplayAlerts = False
objExcel.Workbooks.Open SfileExcel
RowsCount = objExcel.Activesheet.UsedRange.Rows.count
ColsCount = objExcel.Activesheet.UsedRange.Columns.count
iRow = 1
Set objfich = fso.OpenTextFile(txtFile, 2, True)
Do Until iRow > RowsCount
tmpText = ""
For X = 1 To ColsCount
tmpText = tmpText & objExcel.Cells(iRow, X).Value & Delim
Next
objfich.writeline tmpText
iRow = iRow + 1
Loop
objfich.Close
objExcel.Quit
Set objExcel = Nothing
End Sub
'========================================
Sub TestFiles(File1, File2)
Dim oFile1, oFile2, Lig1, Lig2, Ligne, Col, ErrTxt
Set oFile1 = fso.OpenTextFile(File1, 1, True)
Set oFile2 = fso.OpenTextFile(File2, 1, True)
ligne = 1
ErrTxt = ""
Do While Not (oFile1.AtEndOfStream) And Not oFile2.AtEndOfStream
Lig1 = Split(oFile1.ReadLine, Delim)
Lig2 = Split(oFile2.ReadLine, Delim)
For Col = 0 To Ubound(Lig1)
If StrComp(Lig1(Col), Lig2(Col), 0) <> 0 Then
ErrTxt = ErrTxt & "Cellule(" & Ligne & ", " & Col+1 & ")" & vbNewLine
' Col+1 car on part de 0 pour col alors que les colonnes commencent à 1
End If
Next
Ligne = Ligne + 1
Loop
If ErrTxt <> "" Then MsgBox ErrTxt, vbInformation, "Cellules différentes"
End Sub |