批量比较两个excel表

时间:2015-01-06 10:43:25

标签: excel batch-file vbscript

我需要在两张纸之间自动进行比较,如果在批处理过程中不匹配,则需要发送电子邮件。我的表格如下:

                                       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实现这一点。然后我可以使用&#34; cscript myvbscript.vbs&#34;来调用脚本。批处理自动执行此操作。

0 个答案:

没有答案