+ Reply to Thread
Results 1 to 4 of 4

running macro on time not working

Hybrid View

  1. #1
    Registered User
    Join Date
    07-29-2008
    Location
    USA
    Posts
    11

    running macro on time not working

    I have tried 3 different ways to run a macro on time and all have done the same thing. the macro runs 2,3 or even 4 times when it executes.
    when I run the macro alone it works fine. when I run with just one line of code to start the macro it also works ok. but when I try to run more then one line to execute the macro the macro runs multipull times. Can any one fix this for me??

    Application.OnTime ("07:05:00"), "macro1"
    Application.OnTime ("07:09:00"), "macro1"
    Application.OnTime ("07:10:00"), "macro1"
    Application.OnTime ("07:12:00"), "macro1"
    Last edited by VBA Noob; 07-31-2008 at 07:39 AM.

  2. #2
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264
    Hi

    try wrapping those times in the TimeValue function and adding today's date:

    Application.OnTime Date+TimeValue("07:05:00"), "macro1"
    Application.OnTime Date+TimeValue("07:09:00"), "macro1"
    Application.OnTime Date+TimeValue("07:10:00"), "macro1"
    Application.OnTime Date+TimeValue("07:12:00"), "macro1"
    This should schedule Macro1 to be run at 7:05am, 7:09am, 7:10am and 7:12am of the current day.

    Richard

  3. #3
    Registered User
    Join Date
    07-29-2008
    Location
    USA
    Posts
    11

    Smile

    Thank you
    It is working fine. But why didn't the other way work.

  4. #4
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264
    VBA didn't recognise your string times as proper datetimes (I presume) and therefore may have simply run the macros immediately. This would be my guess anyway

    Richard

+ 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