LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Application.OnTime -- Unable to Pass Macro with Numeric Parameter

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.mcrExtractIntraD ata 1'"
Application.OnTime NextIntradayTime, _
"'g:\temp\book3.xls'!'module2.mcrExtractIntraD ata 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

In article ,
says...
Tushar,

It worked for me as well - good find. Must be the "!" that is causing the
problem or it just doesn't like to include the workbook name.


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass date parameter into MS Query Richard Edwards Excel Discussion (Misc queries) 2 June 20th 08 11:43 AM
Is it possible to pass a parameter into IN operator in Query? DennisS Excel Discussion (Misc queries) 0 June 26th 07 09:27 AM
How to pass a workshhet name as a parameter into a subroutine ? yigalb Excel Discussion (Misc queries) 4 January 9th 05 10:28 AM
Pass Parameter to Access Query Al Excel Programming 3 April 29th 04 10:15 AM
unable to close macro using auto_close or application.quit gloria Excel Programming 1 January 14th 04 07:50 AM


All times are GMT +1. The time now is 09:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"