Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: How to automatically run a macro at a specific time?

  1. #1
    Guest

    Default

    I want to run a macro at a user specified time. I tried defining a variable as =NOW() and then setting up ado loop statement to say that if the variable equals the user defined time, then run the macro but that jsut seemed to crash my computer.
    Any ideas?

    Regards

  2. #2
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,700
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I use something like this:

    Public RunWhen As Double
    Public Const cRunWhat = "The_Sub"

    Sub StartTimer()
    RunWhen = Range("c3")
    Application.OnTime earliesttime:=RunWhen, procedure:=cRunWhat, _
    schedule:=True
    End Sub

    Sub The_Sub()
    MsgBox ("Does this Work?")
    End Sub

    Sub StopTimer()
    On Error Resume Next
    Application.OnTime earliesttime:=RunWhen, _
    procedure:=cRunWhat, schedule:=False
    End Sub


    Then I set up range("c3") to equal something like:

    3/4/2002 10:08:00 AM

    Start the process by simply running "Sub StartTimer()".

    But I would set the timedate for sometime in the future, versus now. "Sub The_Sub()" is your procedure to run at the given time.

    Hope this helps. Cheers,

    Nate

    [ This Message was edited by: NateO on 2002-03-04 08:16 ]

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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