VBA复制粘贴应用程序正常运行

时间:2017-04-28 16:23:30

标签: excel vba

我需要你的帮助...我想在同一张纸上将值从一个单元格复制粘贴到另一个单元格,这个过程要在一段时间内完成(例如:1分钟,5分钟)分钟)。能不能给我一个建议,这是我迄今为止完成的代码(复制但不更新):

Sub F_update()

Dim CurrentWS As Worksheet
Set CurrentWS = ThisWorkbook.ActiveSheet
Application.ScreenUpdating = False

Range("A2:A5").Copy Range("B2")
Application.OnTime Now + TimeValue("00:00:20"), _
               "VBAProject.Module1.LB"  

CurrentWS.Activate
Application.ScreenUpdating = False
End Sub

1 个答案:

答案 0 :(得分:0)

您可以使用application.OnTime函数。 将代码添加到ThisWorkBook

Private Sub Workbook_Open()

    runTime_1 = Now + TimeValue("00:01:00")
    Application.OnTime runTime, "RunEvent_1"

    runTime_5 = Now + TimeValue("00:05:00")
    Application.OnTime runTime, "RunEvent_5"

    runTime_10 = Now + TimeValue("00:10:00")
    Application.OnTime runTime, "RunEvent_10"

End Sub


'Then have a macros in the workbook to repeat the Ontime command.

Public Sub RunEvent_1()

    'Execute your actions here'
    ' and repeat hear
    DoEvents ' this gives user control if they needs to break exection
    alertTime = Now + TimeValue("00:01:00")
    Application.OnTime alertTime, "RunEvent_1"
End Sub

Public Sub RunEvent_5()
    'Execute your actions here'
    ' and repeat hear
    DoEvents ' this gives user control if they needs to break exection
    alertTime = Now + TimeValue("00:05:00")
    Application.OnTime alertTime, "RunEvent_5"
End Sub

Public Sub RunEvent_10()
    'Execute your actions here'
    ' and repeat hear
    DoEvents ' this gives user control if they needs to break exection
    alertTime = Now + TimeValue("00:10:00")
    Application.OnTime alertTime, "RunEvent_10"
End Sub