批量比较两个Excel表

如果在批处理过程中不匹配,我需要在两张表之间自动比较,然后发送电子邮件。 我的表看起来像这样:

Head1 Head1 Head1 Column1 Column2 Column3 Head2 Head2 Head2 Head3 Head3 Head3 Head4 Head4 Head4 Info1 Info2 Info3 Info4 Row1 100 1,001 2,001 Info1 Info2 Info3 Info4 Row2 101 1,002 2,002 Info1 Info2 Info3 Info4 Row3 102 1,003 2,003 Info1 Info2 Info3 Info4 Row3 103 1,004 2,004 Info1 Info2 Info3 Info4 Row4 104 1,005 2,005 

所以,虽然我有vba代码(目前使用msgbox,但将被修改为电子邮件收件人):

 Option Explicit Dim ws As Worksheet Dim rw As Long, col As Long, lastrw As Long, lastcol As Long Sub CompareData() For Each ws In Workbooks("Book1.xlsm").Worksheets lastrw = ws.Cells.SpecialCells(xlCellTypeLastCell).Row lastcol = ws.Cells.SpecialCells(xlCellTypeLastCell).Column rw = 6 With Workbooks("Book2.xlsm").Sheets(ws.Name) Do Until rw > lastrw col = 6 Do Until col > lastcol If ws.Cells(rw, col).Value <> .Cells(rw, col).Value Then MsgBox "Values don't match!" Exit Sub End If col = col + 1 Loop rw = rw + 1 Loop End With Next MsgBox "All sheets match" End Sub 

现在我不知道如何通过vbscipt实现这一点。 然后我可以批量调用脚本使用“cscript myvbscript.vbs”自动执行此操作。