+ Reply to Thread
Results 1 to 15 of 15

Auto run macros at a given time error

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Auto run macros at a given time error

    I have two macros namely "sort' and 'anniversary". I want to run these two macros once every day at given time one by one first 'sort' and then 'anniversary'. The code is not giving error but the macros are not running at a given time every day.Please find the error and send me a corrected file.
    I don't want to run the macros after that in a day till next day at given time.

    Mukesh
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,703

    Re: Auto run macros at a given time error

    Look at this link

    http://p2p.wrox.com/excel-vba/71210-...ific-time.html
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Auto run macros at a given time error

    I have already used the workbook open event but the only "sort" macro is running at a given time and not "anniversary" macro. I want to run both macros one by one run automatically at a given time automatically. My problem is that I have to run both macros at a given time automatically. The code accepts only first 'sort' macro and not second 'anniversary' macro. Please see my attachment for reference.
    Solution please!


    Thank you.

    Mukesh

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,703

    Re: Auto run macros at a given time error

    Try this:
    Private Sub Workbook_Open()
    Application.OnTime TimeValue("07:05:00"), "Sort"
    Call Module1.Anniversary
    
    End Sub

  5. #5
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Auto run macros at a given time error

    No, Sorry, only 'sort' macro is running at a given time. 'anniversary' macro is not running after 'sort' macro.
    I search on net but I didn't get any answer. Is there any solution to run two macros one by one automatically at a given time?

    Mukesh

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,703

    Re: Auto run macros at a given time error

    Another option to try
    Private Sub Workbook_Open()
    Application.OnTime TimeValue("07:05:00"), "Sort"
    Application.OnTime EarliestTime:=TimeValue("07:05:01"), Procedure:= Anniversary, LatestTime:=TimeValue("07:55:00")
    End Sub

  7. #7
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Auto run macros at a given time error

    It's giving error 'expected function or variables'. The time is 07:05:00 and not 07:55:01.
    Solution please.

    Mukesh

  8. #8
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,703

    Re: Auto run macros at a given time error

    I used 07:55:01 so that it did not conflict with the first item. I wanted it to run one second after the first first.

  9. #9
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Auto run macros at a given time error

    Thank you Alan.
    Please see my file and correct my mistake please.
    Thank you.

    Mukesh
    Attached Files Attached Files

  10. #10
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,703

    Re: Auto run macros at a given time error

    Ran this with no errors. But I don't know what you want your end result to look like.

    Private Sub Workbook_Open()
    Application.OnTime TimeValue("07:05:00"), "Sort"
    MsgBox "Sort Complete"
    Application.OnTime EarliestTime:=TimeValue("07:05:01"), Procedure:="Anniversary", LatestTime:=TimeValue("07:55:00")
    End Sub

  11. #11
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Auto run macros at a given time error

    Good morning Alan,
    I don't know what is wrong but still it's giving error 'function or variable required".
    Please change the required change in my file and send it to me. What do you mean earliest time '07:55:00'
    I want the macro to be run once daily at a given time.
    First sort and then anniversary.
    I don't want to be run it after that in a daytill next day at given time.
    These are the only requirements of my program.

    Please check the file and sort out the problem.

    Thanking you in anticipation.

    Mukesh

  12. #12
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,703

    Re: Auto run macros at a given time error

    I apologize but I do not know what the issue is with your code. I have attempted to correct to the best of my knowledge. The code for the second module anniversary is set to run one second after the first one but no later than 55 minutes after the first one. I did this because I did not know how long it will take for the first module to run. Suggest you do some google searches on auto run of codes. I see nothing wrong and do not have an alternate solution for you. Does the anniversary module run on its own?

    Good luck.

  13. #13
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Auto run macros at a given time error

    the code you uploaded missed the quotes ".."around the procedure name of Anniversary...it should look like this "Anniversary", otherwise, it gives the the error you are recieving, the name is a text parameter, and you are trying to pass an undeclared; empty variable instead...

    Hope this helps

    EDIT-
    If you had added
    OPTION EXPLICIT
    at the top of the page, you would have recieved a "Undeclared Variable" type error, which would have made this an easier trace
    Last edited by dredwolf; 06-18-2013 at 02:27 AM.
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

  14. #14
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,096

    Re: Auto run macros at a given time error

    And, to be honest, I would not use an Excel/VBA reserved word ... Sort ... as a subroutine name. Bound to be confusing.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  15. #15
    Forum Contributor
    Join Date
    12-15-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    672

    Re: Auto run macros at a given time error

    Dear All,
    Thank you for guidance and solving my problem. Due to my spelling mistake in code the error is coming. Now I have corrected it and it's working fine as per my expectation.
    Sorry for trouble.

    Thank you.

    Mukesh

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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