Consulting

Results 1 to 5 of 5

Thread: Run a macro at a specific time and day

  1. #1
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    Run a macro at a specific time and day

    I'm trying to get this macro to run every Tuesday at 6:02 PM

    This is what I have;

    Private Sub Workbook_Open()
        If Day(Now) = 3 Then
            Application.OnTime TimeValue("18:02:00"), "MyMacro"
        End If
    End Sub
    
    Sub MyMacro()
        Application.OnTime TimeValue("18:02:00"), "MyMacro"
        MsgBox Now()
    End Sub
    I tried it for different days and it still doesn't work. Any ideas why it doesn't work. Need help.

    Thanks

  2. #2
    VBAX Mentor
    Joined
    Jun 2004
    Posts
    363
    Location
    You don't specify in which way it doesn't work. Do you receive an error? Does nothing happen?

    Are you putting the second sub into a standard module?

    If I put the Workbook_Open routine in the ThisWorkBook module and the second sub in a standard module, I receive the Msgbox at the appointed time.

  3. #3
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    Run a macro at a specific time and day

    Nothing happens. I don't get a message box or anything.

  4. #4
    VBAX Mentor
    Joined
    Jun 2004
    Posts
    363
    Location
    Do you have the subs in the correct location? Are macros enabled for the workbook? Is the workbook open at 6:02?
    The attached file should display the message at 8:02 pm

  5. #5
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    Run a macro at a specific time and day

    Yours worked. Still cant figure out why mind didn't.

    Thanks

Posting Permissions

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