Hi Tom,
It appears one has to get the single and double quotes just right. I
tested with the called routine in the same module, in another module,
and in two different modules in a different workbook. Here's a
summary.
But before that, a note about the use of this undocumented feature
(trick?). At least the first version shown below (i.e., without
specifying the workbook or module) works with:
* the OnAction property of a forms(?)/commandbar(?) control,
* XL's OnKey method (coincidentally, I tested it a few days ago), and
* XL's OnTime method.
In any case, back to the tests with OnTime...
I had a function similar to the one below in each of the four modules
(module1 and module2 in the workbook scheduling the calls, and module1
and module2 in another workbook).
Public Sub mcrExtractIntraData(bteIntraday As Byte)
MsgBox "Same module " & bteIntraday
End Sub
Each subroutine differed only by the string literal part. That made it
possible to identify which function was actually called.
We already know that testIt1 works.
Sub testIt1()
Dim NextIntradayTime As Date
NextIntradayTime = Now + TimeValue("00:00:03")
Application.OnTime NextIntradayTime, "'mcrExtractIntraData 1'"
End Sub
The next was to call the subroutine in another module. The correct
syntax is shown in testIt2.
Sub testIt2()
Dim NextIntradayTime As Date
NextIntradayTime = Now + TimeValue("00:00:03")
Application.OnTime NextIntradayTime, _
"'module2.mcrExtractIntraData 1'"
End Sub
The next was to call the subroutine in another workbook. The correct
syntax turned out to be:
Sub testIt3()
Dim NextIntradayTime As Date
NextIntradayTime = Now + TimeValue("00:00:03")
Application.OnTime NextIntradayTime, _
"'g:\temp\book3.xls'!'module1.mcrExtractIntraData 1'"
Application.OnTime NextIntradayTime, _
"'g:\temp\book3.xls'!'module2.mcrExtractIntraData 1'"
End Sub
I discovered the workbook has to be saved. If it is not and the
workbook name is specified as jsut 'book3', XL/VBA tries book3.xls and
book3.htm and, obviously, fails in both cases.
As a final test, I scheduled a call to a subroutine that expected a
string argument. It worked with the syntax below:
Sub testIt4()
Dim NextIntradayTime As Date
NextIntradayTime = Now + TimeValue("00:00:03")
Application.OnTime NextIntradayTime, _
"'g:\temp\book3.xls'!'SubWithStringParam ""1""'"
End Sub
--
Regards,
Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions