1. 程式人生 > >比較兩個sheet頁中的內容,自動切換

比較兩個sheet頁中的內容,自動切換

比較兩個sheet中的內容,一般是一個長圖片

Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal DwMilisconds As Long)

Sub 畫像比較()

    Call compare("Sheet1", "Sheet2", 3000, 5)
    
End Sub



Private Sub compare(sheet1Name As String, sheet2Name As String, maxLineNumber As Integer, maxCompareCount As Integer)
    
    Dim lineNumber As Integer: lineNumber = 1
    Dim compareCount As Integer: compareCount = 0
    
    Do While lineNumber < maxLineNumber
        
        loopcount = loopcount + 1
        
        Application.Sheets(sheet1Name).Activate
        Application.StatusBar = "シート名:" & sheet1Name & "_lineNumber:" & lineNumber & "_compareCount:" & loopcount
        ActiveWindow.ScrollRow = lineNumber
        ActiveWindow.ScrollColumn = 1
        DoEvents
        Sleep 500
        
        Application.Sheets(sheet2Name).Activate
        Application.StatusBar = "シート名:" & sheet2Name & "_lineNumber:" & lineNumber & "_compareCount:" & loopcount
        ActiveWindow.ScrollRow = lineNumber
        ActiveWindow.ScrollColumn = 1
        DoEvents
        Sleep 500
        
        If loopcount Mod maxCompareCount = 0 Then
            '位置移動
            lineNumber = lineNumber + 40
            loopcount = 0
        End If
    Loop
    
End Sub

這裡面,有一個 64位系統 與 32位系統需要區別的注意點。

Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal DwMilisconds As Long)

64位系統時,需要使用上面的   PtrSafe