+ Reply to Thread
Results 1 to 8 of 8

Run a macro only once a day

  1. #1
    Forum Contributor
    Join Date
    07-01-2012
    Location
    ZA
    MS-Off Ver
    Excel 2013
    Posts
    300

    Run a macro only once a day

    Hi everyone

    Got a question for the VBA fundis.......is there a way or some code that you can force a macro to ONLY run once in 24hrs....so it will execute once a day -if its run again it wont run. I was just wondering if that is possible to code in VBA.....example Have a macro called Test......the test macro can only run once a day......if its run within 24hrs again it wont execute as it already ran.

    If this is possible I would appreciate a solution -rep given for you help

    Many thanks

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Run a macro only once a day

    If you add a include the code to write the date to a specific cell the moment the macro is run then you first test if the date = today's date then exit else run the macro and update the cell with the date
    Hope this answers your question, of course this only works if you open the Excel workbook
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Contributor
    Join Date
    07-01-2012
    Location
    ZA
    MS-Off Ver
    Excel 2013
    Posts
    300

    Re: Run a macro only once a day

    found this code

    Please Login or Register  to view this content.
    So if I replace the Msgbox with

    Call test

    Will this check it wont run again ?

  4. #4
    Forum Contributor
    Join Date
    07-01-2012
    Location
    ZA
    MS-Off Ver
    Excel 2013
    Posts
    300

    Re: Run a macro only once a day

    Quote Originally Posted by Keebellah View Post
    If you add a include the code to write the date to a specific cell the moment the macro is run then you first test if the date = today's date then exit else run the macro and update the cell with the date
    Hope this answers your question, of course this only works if you open the Excel workbook
    Thank you for your suggestion......see the code I got -I simply dont want the macro Test to run a second time -only once a day

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Run a macro only once a day

    The code is fine but you can simplify it to this :

    Please Login or Register  to view this content.
    Just test if A1 = today's date, if not run the macro and then set A1 = date
    so when you run it again it won't run

  6. #6
    Forum Contributor
    Join Date
    07-01-2012
    Location
    ZA
    MS-Off Ver
    Excel 2013
    Posts
    300

    Re: Run a macro only once a day

    Quote Originally Posted by Keebellah View Post
    The code is fine but you can simplify it to this :

    Please Login or Register  to view this content.
    Just test if A1 = today's date, if not run the macro and then set A1 = date
    so when you run it again it won't run
    In Cells A1 should I place =Today(). -I ran it and it executes twice ?????So its not doing it correctly what am I missing ?

  7. #7
    Forum Contributor
    Join Date
    07-01-2012
    Location
    ZA
    MS-Off Ver
    Excel 2013
    Posts
    300

    Re: Run a macro only once a day

    I manage to fix this



    This is the code
    Please Login or Register  to view this content.
    After the formula is placed in the cell it did not run again

  8. #8
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Run a macro only once a day

    Great, so it's solved?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] macro showing error ( macro not found ) while trying to execute macro every 1 minute
    By prabhuduraraj09 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2018, 07:58 PM
  2. [SOLVED] Define variable in macro than calling that macro inside another macro
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-21-2015, 10:58 AM
  3. Using a macro on workbook1 to create a button in wb2 and assigning macro "wb2!macro"
    By penfold1992 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2014, 11:39 AM
  4. [SOLVED] Macro to show Which macro didnt work in a nested macro
    By akhileshgs in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-10-2013, 03:21 AM
  5. Perform macro "on open" specific file- store macro in Personal Macro Workbook?
    By thompssc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-17-2012, 12:38 PM
  6. lookup macro, solver macro, realtime macro
    By xelhelp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-02-2011, 06:14 PM
  7. Cannot find macro error when running a macro from a macro in a diffrent workbook.
    By Acrobatic82 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-05-2010, 09:22 AM

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