This is a followup on this question/answer/comment...
I'm trying to force code execution of my first procedure (a procedure without input variables) by using Application.Ontime to start a second procedure (a procedure with input variables). Since Application.Ontime can only "call" a macro/procedure which doesn't allow for input variables I must use a global variable to pass on the input parameter to the second macro/procedure called by Application.Ontime (see the frist, working example). It works but I rather don't work with a global variable.
I thought I'm smart and I use a "pseudo-macro in-between" which only exists to forces the code from the first procedure to get executed before the second procedure starts. But it doesn't work: the code execution isn't completed by the time the second procedure gets started. Is the problem that I use an empty pseudo-macro? I tried different commands in the pseudo macro, but it didn't make any differences. Any ideas? (see second, not working example)
Frist example, which works (code gets executed before the macro):
Public gloInputVariable as Variant
Sub procedureWithoutInputparameters
'Do something in this procedure
inputVariable = "something"
'force code execution
'workaround with global variable instead of inputparameter (macros don't have input parameters)
gloInputVariable = "something"
'start the next procedure as a macro (basicaly a procedure without input paramters)
Application.OnTime Now + TimeSerial(0, 0, 1), "WorkaroundMacroInsteadOfProcedureWithInputParameters"
End Sub
Sub WorkaroundMacroInsteadOfProcedureWithInputParameters()
'get the input parameter through a global variable
variable1 = gloInputVariable
'do something
End Sub
Second example, which doesn't work (code from the first procedure is not completely executed before the second procedure starts):
Sub procedureWithoutInputparameters
'Do something in this procedure
inputVariable = "something"
'force code execution through pseudomacro (this doesn't work)
'force execution through macro
Application.Ontime Now + TimeSerial(0, 0, 1), "Pseudomacro"
'run next second procedure procedure
procedureWithInputparamters (inputVariable)
End Sub
Sub PseudoMacro()
'do nothing, pseudo-macro is only here to force code execution before starting the second procedure with input parameters
End Sub
Sub procedureWithInputparamters(strSomeInputString as String)
'get the input parameter "directly"
variable1 = strSomeInputString
'do something
End Sub