+ Reply to Thread
Results 1 to 13 of 13

Automatically run macro at a particular time

Hybrid View

ammei Automatically run macro at a... 06-15-2013, 06:24 AM
Moo the Dog Re: Automatically run macro... 06-15-2013, 07:28 AM
apo Re: Automatically run macro... 06-15-2013, 07:32 AM
ammei Re: Automatically run macro... 06-15-2013, 07:51 AM
apo Re: Automatically run macro... 06-15-2013, 08:11 AM
ammei Re: Automatically run macro... 06-15-2013, 08:16 AM
apo Re: Automatically run macro... 06-15-2013, 08:26 AM
ammei Re: Automatically run macro... 06-15-2013, 08:27 AM
ammei Re: Automatically run macro... 06-15-2013, 08:59 AM
apo Re: Automatically run macro... 06-15-2013, 09:12 AM
ammei Re: Automatically run macro... 06-15-2013, 09:20 AM
apo Re: Automatically run macro... 06-15-2013, 09:28 AM
apo Re: Automatically run macro... 06-16-2013, 05:59 AM
  1. #1
    Registered User
    Join Date
    06-15-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    7

    Automatically run macro at a particular time

    hi

    I would like to run a macro at every day 4.15 am



    I have inserted following code to workbook

    Private Sub Workbook_Open()
    
    
    Application.OnTime TimeValue("04:15:00"), "Saveas()"
    
    End Sub
    its not working..can anyone help me please..
    Last edited by ammei; 06-15-2013 at 06:48 AM.

  2. #2
    Forum Expert Moo the Dog's Avatar
    Join Date
    09-28-2012
    Location
    Wisconsin
    MS-Off Ver
    Office 365 (PC & Mac)
    Posts
    1,845

    Re: Automatically run macro at a particular time

    Remove the () from Saveas()

    And if it isn't already, try placing the 'Saveas' macro in its own module, and that 'Saveas' is a Public Sub, not Private.

    It works fine for me when I do those things... but I am on a Mac - so not sure if that translates to a PC.

    - Moo

  3. #3
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Automatically run macro at a particular time

    Hi..
    Try changing this..

    Application.OnTime TimeValue("04:15:00"), "Saveas()"
    to this..

    Application.OnTime TimeValue("04:15:00"), "Saveas", Schedule:=True
    I Agree with Moo the Dog.. remove the ()
    Last edited by apo; 06-15-2013 at 07:35 AM. Reason: typo

  4. #4
    Registered User
    Join Date
    06-15-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Automatically run macro at a particular time

    i have already remove the ()
    and did as u said..still not working..:/

  5. #5
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Automatically run macro at a particular time

    Hi..

    What exactly not working?

    The Call to the Save Routine OR

    the Save routine itself?

    Try replacing your Saveas Routine with something simple like:
    Sub Saveas()
    MsgBox "Hi"
    End Sub
    If you see the message box.. then you can narrow down that your issue is with the actual save routine and not the timer..

  6. #6
    Registered User
    Join Date
    06-15-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Automatically run macro at a particular time

    the problem is with the Call to the Save routine..

  7. #7
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Automatically run macro at a particular time

    Hi..

    I am attaching a simple example of calling a MsgBox at a specific time..

    Just set the time to trigger the MsgBox in this line:
    dTime = TimeValue("22:23:00")
    Press the "Start Timer" button to initiate the process....

    Hopefully that will get you where you need to be..
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    06-15-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Automatically run macro at a particular time

    ok..thanks..

  9. #9
    Registered User
    Join Date
    06-15-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    7

    Thumbs down Re: Automatically run macro at a particular time

    Values.xlsm

    i have attached a sheet..can u show me on this how to automatically save the contents of cell values in a folder when it reach 4.15 AM

  10. #10
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Automatically run macro at a particular time

    Hi.. Yeap.. no worries.. its late here.. will have a stab at it tomorrow..
    one thing.. when you say.. "contents of cell values".. what do you mean?

    Be specific... do you mean (using you sample sheet as an example).. you want to save the contents of B12 when the timer reaches 4.15 am?

    And if so.. you could copy that value to a new Workbook and then save it to the folder you want.. ?



    Please clarify...

  11. #11
    Registered User
    Join Date
    06-15-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Automatically run macro at a particular time

    i want to automatically save the contents of B4 to B12 to another worksheet and save it in a folder when is 4.15 AM.

  12. #12
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Automatically run macro at a particular time

    k. clear.. will do it tomorrow.. (unless someone else cracks it for you before..).

    i want to automatically save the contents of B4 to B12 to another worksheet and save it in a folder when is 4.15 AM.
    You can't save a Worksheet to a folder.. yes.. you can save it to a WorkBook and save it in a folder.. the point i am making is that it is best to be precise and get your terminology correct so you will get the best help available..

    see you tomorrow...

  13. #13
    Valued Forum Contributor
    Join Date
    03-22-2013
    Location
    Australia,NSW, Wirrimbi
    MS-Off Ver
    Excel 2013
    Posts
    1,057

    Re: Automatically run macro at a particular time

    Hi..

    Put this in a Module..
    Sub Saveas()
    Dim ShNames As Variant
    ShNames = Array("Sheet1", "Sheet2", "Sheet3")
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    Sheets("Sheet1").Range("B4:B12").Copy Destination:=Sheets("Sheet2").Range("B4")
    Set NewWkbk = Workbooks.Add
            ThisWorkbook.Sheets("Sheet2").Copy Before:=NewWkbk.Sheets(1)
            NewWkbk.Sheets(1).Name = "Data"
            Worksheets(ShNames).Delete
            NewWkbk.Saveas ThisWorkbook.Path & "\" & Format(Now, "long date")
            NewWkbk.Close
    
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    End Sub
    And add this to your Sheet code to call it at 4:15 AM..
    Private Sub Worksheet_Activate()
    Application.OnTime TimeValue("04:15:00"), "Saveas", Schedule:=True
    End Sub
    Attached Files Attached Files

+ 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