+ Reply to Thread
Results 1 to 11 of 11

Macro will not launch using Application.OnTime TimeValue

  1. #1
    Registered User
    Join Date
    01-07-2012
    Location
    Wichita, KS
    MS-Off Ver
    Excel 2010
    Posts
    5

    Macro will not launch using Application.OnTime TimeValue

    [Solved]
    I am using the function: Application.OnTime TimeValue to run a specific macro every day at 4:00 PM, but at 4:00 PM the macro tries to launch another macro but is disabled by Excel even though the macro security is set to allow it to run. If I run the “Sample_Macro_Name” manually, it runs just fine. However, as soon as I use the another macro to launch the “Sample_Macro_Name” at a specific time, when the that time occurs, instead it returns the error message:

    "Cannot run the macro Sample_Macro_Name() The macro may not be available in this workbook or all macros may be disabled”

    Excel version: Office 2010
    Macro security: set to enable all macros to be run.
    Workbook is saved as a macro enabled workbook in a “trusted file location” on my local drive.

    I have tried placing the 2nd bit of code, the macro, in standard modules, worksheet modules, and ThisWorkbook module, but in every case the macro will not fire with the Application.OnTime function, but will always fire when I manually launch it. It is as if Microsoft does not allow timed macros to fire off at a certain time due to security, yet it can be manually launched.

    Please Login or Register  to view this content.
    Folks, I appreciate your wise guidance.
    Last edited by Josh Colton; 01-07-2012 at 05:59 PM.

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,275

    Re: Macro will not launch using Application.OnTime TimeValue

    Josh,

    Works OK on my 2010 system. Possibly, you have a corrupted workbook?

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,643

    Re: Macro will not launch using Application.OnTime TimeValue

    Question: That last "double quote": (”) after the macro name has a code value of 148, while a (") has a code value of 34; where did that (”) come from?
    The VB editor puts a regular " at the end of the line so that other symbol may be seen as a part of the macro name but it is missing from the actual macro; also, the () in the calling line are not needed.
    Ben Van Johnson

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro will not launch using Application.OnTime TimeValue

    Hello Josh,

    Welcome to the Forum!

    You did not say if the second macro is in the same workbook. If it is not then the other workbook must be open and you must qualify the macro name with the name of the workbook it is in. Application.OnTime will not run if the workbook is not open.
    Last edited by Leith Ross; 01-07-2012 at 04:29 PM.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  5. #5
    Registered User
    Join Date
    01-07-2012
    Location
    Wichita, KS
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro will not launch using Application.OnTime TimeValue

    test.xlsm

    Had to take a break for a few hours out of frustration. Thanks guys. It is good to know that this running on another Excel 2010 system.

    I have uploaded a test worksheet for which you can see the code. The prior code was copied from the original into my post and edited a bit to change the macro names which is why I had the quotation mark wrong.

    I tried a re-boot of my system.
    I created a fresh workbook (attached)
    I disabled my anti-virus temporarily to test (to rule that out)

    I still get the same error.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro will not launch using Application.OnTime TimeValue

    Hello Josh,

    Try this version of the macro. Generally, macros that are for general use are placed in standard VBA modules. This macro resides in the "Sheet1" module so you must qualify the call.
    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,643

    Re: Macro will not launch using Application.OnTime TimeValue

    This one triggers the ontime event and runs ok:
    (I moved the macro_name.. to a standard module from the sheet module.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    01-07-2012
    Location
    Wichita, KS
    MS-Off Ver
    Excel 2010
    Posts
    5

    Wink Re: Macro will not launch using Application.OnTime TimeValue

    Woo Hoo! Thanks, resolved. It was a naming issue. I put () after the macro name, and I notice you folks did not. So it was not finding it.
    Really appreciate it.



    Now, if I want the macro to run every day at 4:00 PM, and not just the first time the workbook opens, will it automatically do that, or will I need to put some kind of loop on it so it runs each day at 4:00?

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Macro will not launch using Application.OnTime TimeValue

    Hello Josh,

    Application.OnTime by default schedules the macro the run. This means as long as the workbook is open, the macro will be run again at the same time.

  10. #10
    Registered User
    Join Date
    01-07-2012
    Location
    Wichita, KS
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro will not launch using Application.OnTime TimeValue

    Thanks all. [Solved] --- not sure how to mark solved from the interface.

  11. #11
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Macro will not launch using Application.OnTime TimeValue

    I confess I was under the impression that OnTime will only run once as it assumes today's date if you do not specify a date. Unless your called code reschedules it, the code will only be run once, I believe. If this is incorrect can someone please let me know? (easier than me testing it over 24 hours)
    Good luck.

+ 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