拥有Excel自动滚动宏;有没有办法把计时器放在上面?

时间:2018-06-11 18:00:48

标签: excel vba excel-vba

所以这就是我对自动滚动宏的看法:

Sub Macro12()
    Dim lastRow As Long, i As Long
    lastRow = Range("A" & Rows.Count).End(xlUp).Row

    For i = 1 To 23 Step 2
        Cells(i, 1).Select
        ActiveWindow.SmallScroll down:=2
        Application.Wait (Now + TimeValue("0:00:02")) 'Wait two seconds before 
        continuing.
        If i = lastRow - 2 Or i = lastRow - 1 Then
            i = 0
            Cells(1, 1).Select
        End If
    Next i
    Debug.Print (i)
End Sub

这个问题是它最终会冻结并崩溃Excel。我想要找到的是一个定时器代码,它将告诉它每隔60-90秒运行一次宏。 IE:运行Macro12,然后不要90秒,再次运行,冲洗重复。

我该怎么做?

编辑:

此代码有效:

Sub ReRunMacro()
    Dim xMin As String
    Dim lastRow As Long, i As Long
    lastRow = Range("A" & Rows.Count).End(xlUp).Row

    For i = 1 To 13 Step 2
        Cells(i, 1).Select
        ActiveWindow.SmallScroll down:=2
        Application.Wait (Now + TimeValue("0:00:02"))
        If i = lastRow - 2 Or i = lastRow - 1 Then
            i = 0
            Cells(1, 1).Select
        End If
    Next i
    Debug.Print (i)

    xMin = GetSetting(AppName:="Kutools", Section:="Macro", Key:="min", Default:="")
    If (xMin = "") Or (xMin = "False") Then
        xMin = Application.InputBox(prompt:="Please input the interval time you need to repeat the Macro", Title:="Kutools for Excel", Type:=2)
        SaveSetting "Kutools", "Macro", "min", xMin
    End If

    If (xMin <> "") And (xMin <> False) Then
        Application.OnTime Now() + TimeValue("0:" + xMin + ":0"), "ReRunMacro"
    Else
        Exit Sub
    End If

End Sub

但它不是循环回到第一行(或A1),而是继续前进。在再次运行自动滚动之前,一个简单的Range("A1").Select是否可以循环备份?

0 个答案:

没有答案