Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nmpowell/6b83d522b69e3f3127a1edd0332efeea to your computer and use it in GitHub Desktop.
Save nmpowell/6b83d522b69e3f3127a1edd0332efeea to your computer and use it in GitHub Desktop.
Excel VBA macro to demonstrate mixed argument types (Integer and String) to Application.OnTime.
' Demonstrating mixed argument types to Application.OnTime (Integer and String).
' See these pages for more:
' - http://www.markrowlinson.co.uk/articles.php?id=10
' - https://www.mrexcel.com/forum/excel-questions/81724-calling-procedure-parameters.html
' - https://stackoverflow.com/questions/31439866/multiple-variable-arguments-to-application-ontime
Sub RunMe()
Dim testName As String
Dim counter As Integer
testName = "S"
counter = 0
' String then Integer argument
Call TestRepeat(testName, counter)
' Integer then String argument
Call RepeatTest(counter, testName)
End Sub
Sub TestRepeat(testName As String, counter As Integer)
testName = testName & " " & testName
counter = counter + 1
Debug.Print "TestRepeat: " & testName & ", " & counter
If counter = 4 Then Exit Sub
Application.OnTime Now + TimeValue("00:00:02"), "'TestRepeat """ & testName & """, " & counter & " '"
End Sub
Sub RepeatTest(counter As Integer, testName As String)
testName = testName & " " & testName
counter = counter + 1
Debug.Print "RepeatTest: " & counter & ", " & testName
If counter = 3 Then Exit Sub
Application.OnTime Now + TimeValue("00:00:10"), "'RepeatTest " & counter & ", """ & testName & """ '"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment