I need to run a VBA subroutine 4 seconds later. The subroutine takes one string parameter. The problem I’m having is that the string I need to pass appears to be too long and it’s erroring out. Try running this code:
Sub DoTest()
Application.OnTime Now + TimeSerial(0, 0, 4), "'PrintStr ""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa""'"
End Sub
Sub PrintStr(str As String)
Debug.Print str
End Sub
DoTest() runs without errors. Now add one more “a” to the string of a’s and run DoTest() again. You will get a “This macro … cannot be found” error.
How can I work around this, either using OnTime or another solution that would allow me to call a subroutine that accepts a parameter X number of seconds later? I’m using Excel 2003.
Try something like this: