VBA Excel Application.OnTime将参数传递给过程

时间:2019-03-13 07:25:42

标签: excel vba parameters

我想将参数传递给正在使用Application.OnTime调用的过程

由于在实际代码中只有三个不同的timedEvents仅具有不同的i,所以没有功能为每个i创建一个timedEvent。

我尝试了以下操作,但前面带有注释的操作无效

Sub wait(i As Integer)
    Application.OnTime Now + TimeValue("00:00:10"), "timedEvent" & i
    'Application.OnTime Now + TimeValue("00:00:10"), "timedEvent(i)"
    'Application.OnTime Now + TimeValue("00:00:10"), "timedEvent(" & i & ")"
End Sub

'At the Moment:
Function timedEvent1()
    Dim i As Integer
    i = 1
    Call timedEvent(i)
End Function

Function timedEvent2()
    Dim i As Integer
    i = 2
    Call timedEvent(i)
End Function

Function timedEvent3()
    Dim i As Integer
    i = 3
    Call timedEvent(i)
End Function


'I want to jump directly to this function
Function timedEvent(i As Integer)
    'some code
End Function

0 个答案:

没有答案