+ Reply to Thread
Results 1 to 8 of 8

Application.OnTime -- Unable to Pass Macro with Numeric Parameter

  1. #1
    Butaambala
    Guest

    Application.OnTime -- Unable to Pass Macro with Numeric Parameter

    I am having trouble with Application.OnTime when specifying a Macro
    with Numeric (Byte) parameter. Here is the code:

    macro I'm calling:
    Public Sub mcrExtractIntraData(bteIntraday As Byte)

    Failed attempts:
    1)
    NextIntradayTime = Now + TimeValue("00:01:00")
    strProc = "mcrExtractIntraData" & " 1"
    Application.OnTime NextIntradayTime, strProc

    2)
    NextIntradayTime = Now + TimeValue("00:01:00")
    Application.OnTime NextIntradayTime, "mcrExtractIntraData " & 1

    3)
    NextIntradayTime = Now + TimeValue("00:01:00")
    Application.OnTime NextIntradayTime, "'mcrExtractIntraData 1'"

    Any help greatly appreciated.


  2. #2
    Tom Ogilvy
    Guest

    Re: Application.OnTime -- Unable to Pass Macro with Numeric Parameter

    don't pass a byte. Change your function to expect an integer or a long.

    --
    Regards,
    Tom Ogilvy

    "Butaambala" <brogers75@yahoo.com> wrote in message
    news:1118079157.833481.177040@z14g2000cwz.googlegroups.com...
    > I am having trouble with Application.OnTime when specifying a Macro
    > with Numeric (Byte) parameter. Here is the code:
    >
    > macro I'm calling:
    > Public Sub mcrExtractIntraData(bteIntraday As Byte)
    >
    > Failed attempts:
    > 1)
    > NextIntradayTime = Now + TimeValue("00:01:00")
    > strProc = "mcrExtractIntraData" & " 1"
    > Application.OnTime NextIntradayTime, strProc
    >
    > 2)
    > NextIntradayTime = Now + TimeValue("00:01:00")
    > Application.OnTime NextIntradayTime, "mcrExtractIntraData " & 1
    >
    > 3)
    > NextIntradayTime = Now + TimeValue("00:01:00")
    > Application.OnTime NextIntradayTime, "'mcrExtractIntraData 1'"
    >
    > Any help greatly appreciated.
    >




  3. #3
    Butaambala
    Guest

    Re: Application.OnTime -- Unable to Pass Macro with Numeric Parameter

    thanks, Tom. Ok, so now the macro I'm calling is:
    Public Sub mcrExtractIntraData(intIntraday As Integer)

    All three attempts still fail. Here are the results:
    1) The macro "C:\Test.xls'!mcrExtractIntraData 0' cannot be found.
    2) SAME
    3) Nothing happens at all (procedure not called)


  4. #4
    Tom Ogilvy
    Guest

    Re: Application.OnTime -- Unable to Pass Macro with Numeric Parameter

    There has been some discussion that xl2002 and later did not support this
    construct (it is undocumented which has always meant use at your own risk
    for it may go unsupported). I don't remember the details - but as I said, I
    heard it is no longer supported and I couldn't get it to work in xl2003.

    The syntax that works in earlier versions is:

    Application.OnTime Now() + TimeValue("00:00:05"), _
    "'checkOntime.xls!mcrExtractIntraData 1'"
    End Sub

    to the best of my recollection.

    --
    Regards,
    Tom Ogilvy


    "Butaambala" <brogers75@yahoo.com> wrote in message
    news:1118080371.232268.174150@g14g2000cwa.googlegroups.com...
    > thanks, Tom. Ok, so now the macro I'm calling is:
    > Public Sub mcrExtractIntraData(intIntraday As Integer)
    >
    > All three attempts still fail. Here are the results:
    > 1) The macro "C:\Test.xls'!mcrExtractIntraData 0' cannot be found.
    > 2) SAME
    > 3) Nothing happens at all (procedure not called)
    >




  5. #5
    Tushar Mehta
    Guest

    Re: Application.OnTime -- Unable to Pass Macro with Numeric Parameter

    The foll. works OK with 2003:

    Public Sub mcrExtractIntraData(bteIntraday As Byte)
    MsgBox bteIntraday
    End Sub

    Sub testIt2()
    Dim NextIntradayTime As Date
    NextIntradayTime = Now + TimeValue("00:00:03")
    Application.OnTime NextIntradayTime, "'mcrExtractIntraData 1'"
    End Sub

    --
    Regards,

    Tushar Mehta
    www.tushar-mehta.com
    Excel, PowerPoint, and VBA add-ins, tutorials
    Custom MS Office productivity solutions

    In article <1118079157.833481.177040@z14g2000cwz.googlegroups.com>,
    brogers75@yahoo.com says...
    > I am having trouble with Application.OnTime when specifying a Macro
    > with Numeric (Byte) parameter. Here is the code:
    >
    > macro I'm calling:
    > Public Sub mcrExtractIntraData(bteIntraday As Byte)
    >
    > Failed attempts:
    > 1)
    > NextIntradayTime = Now + TimeValue("00:01:00")
    > strProc = "mcrExtractIntraData" & " 1"
    > Application.OnTime NextIntradayTime, strProc
    >
    > 2)
    > NextIntradayTime = Now + TimeValue("00:01:00")
    > Application.OnTime NextIntradayTime, "mcrExtractIntraData " & 1
    >
    > 3)
    > NextIntradayTime = Now + TimeValue("00:01:00")
    > Application.OnTime NextIntradayTime, "'mcrExtractIntraData 1'"
    >
    > Any help greatly appreciated.
    >
    >


  6. #6
    Tushar Mehta
    Guest

    Re: Application.OnTime -- Unable to Pass Macro with Numeric Parameter

    Hi Tom,

    Maybe others had too, but I for sure did point out it was broken
    w/2002. That was in the context of an argument of a sub assigned to
    the OnAction property of a button.

    However, it started working with some support release of 2002.

    As far as I can recall, MS acknowledged neither the problem nor the
    fix. ;-)

    --
    Regards,

    Tushar Mehta
    www.tushar-mehta.com
    Excel, PowerPoint, and VBA add-ins, tutorials
    Custom MS Office productivity solutions

    In article <epjrKIsaFHA.2128@TK2MSFTNGP14.phx.gbl>, twogilvy@msn.com
    says...
    > There has been some discussion that xl2002 and later did not support this
    > construct (it is undocumented which has always meant use at your own risk
    > for it may go unsupported). I don't remember the details - but as I said, I
    > heard it is no longer supported and I couldn't get it to work in xl2003.
    >
    > The syntax that works in earlier versions is:
    >
    > Application.OnTime Now() + TimeValue("00:00:05"), _
    > "'checkOntime.xls!mcrExtractIntraData 1'"
    > End Sub
    >
    > to the best of my recollection.
    >
    >


  7. #7
    Tom Ogilvy
    Guest

    Re: Application.OnTime -- Unable to Pass Macro with Numeric Parameter

    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.

    --
    Regards,
    Tom Ogilvy

    "Tushar Mehta" <tmUnderscore200310@tushar-mehta.SeeOhEm> wrote in message
    news:MPG.1d0e87c1c52744cb98b00e@msnews.microsoft.com...
    > The foll. works OK with 2003:
    >
    > Public Sub mcrExtractIntraData(bteIntraday As Byte)
    > MsgBox bteIntraday
    > End Sub
    >
    > Sub testIt2()
    > Dim NextIntradayTime As Date
    > NextIntradayTime = Now + TimeValue("00:00:03")
    > Application.OnTime NextIntradayTime, "'mcrExtractIntraData 1'"
    > End Sub
    >
    > --
    > Regards,
    >
    > Tushar Mehta
    > www.tushar-mehta.com
    > Excel, PowerPoint, and VBA add-ins, tutorials
    > Custom MS Office productivity solutions
    >
    > In article <1118079157.833481.177040@z14g2000cwz.googlegroups.com>,
    > brogers75@yahoo.com says...
    > > I am having trouble with Application.OnTime when specifying a Macro
    > > with Numeric (Byte) parameter. Here is the code:
    > >
    > > macro I'm calling:
    > > Public Sub mcrExtractIntraData(bteIntraday As Byte)
    > >
    > > Failed attempts:
    > > 1)
    > > NextIntradayTime = Now + TimeValue("00:01:00")
    > > strProc = "mcrExtractIntraData" & " 1"
    > > Application.OnTime NextIntradayTime, strProc
    > >
    > > 2)
    > > NextIntradayTime = Now + TimeValue("00:01:00")
    > > Application.OnTime NextIntradayTime, "mcrExtractIntraData " & 1
    > >
    > > 3)
    > > NextIntradayTime = Now + TimeValue("00:01:00")
    > > Application.OnTime NextIntradayTime, "'mcrExtractIntraData 1'"
    > >
    > > Any help greatly appreciated.
    > >
    > >




  8. #8
    Tushar Mehta
    Guest

    Re: 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.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

    In article <uYkUdJ2aFHA.2420@TK2MSFTNGP12.phx.gbl>, twogilvy@msn.com
    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.
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1