+ Reply to Thread
Results 1 to 12 of 12

Auto Save - VBA Code or Excel option?

  1. #1
    Forum Contributor
    Join Date
    08-06-2007
    Posts
    105

    Auto Save - VBA Code or Excel option?

    Is there a way to have excel automatically save the workbook every 5 minutes or so? I'm not talking about the backup option (tools-options-save) I mean do a hard save?

    Or would this warrant a timed VBA code? If so, can someone build me one quickly? I'm kinda in a time crunch - sorry for last minute notice

    Co-worker just deleted 8 hours of work bec "she didn't" know to save it....
    Last edited by adgjqetuo; 10-07-2009 at 10:28 AM.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Save - VBA Code or Excel option?

    Place this code in a generl Module

    Please Login or Register  to view this content.
    Place this code in "This Workbook":

    Please Login or Register  to view this content.
    The code will save your workbook every five minutes and will turn off the save when the workbook is closed.

    Hope this helps. J
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Contributor
    Join Date
    08-06-2007
    Posts
    105

    Re: Auto Save - VBA Code or Excel option?

    Thanks for the response! Just a quick question though:

    It does save after 5 minutes, but when I close the workbook, it prompts to save or not. If I hit no, it doesn't save.

    I added "ActiveWorkbook.Save" to the "workbook before close" macro, and that seemed to do the trick. But I noticed you have that already in the "SaveWorkbook" macro - was this souposed to call already? Or am I okay leaving that in there?
    Last edited by adgjqetuo; 10-06-2009 at 11:40 PM.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Save - VBA Code or Excel option?

    This save
    Please Login or Register  to view this content.
    is the save called by the timer. If you make workbook changes within 5 minutes after this runs and then closed the workbook, you'll be asked to save because the changes you made have not been saved by the timer. So, your
    "ActiveWorkbook.Save"
    is entirely appropriate.

    When you researched this subject, I'm certain you became aware of the caveats regarding "auto-save". It saves EVERYTHING. Be cautious if you're still debugging and that user access is limited to cells you want them to change.
    J

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Save - VBA Code or Excel option?

    I put some notes in the code so you can see what it's doing. I made these notes in NotePad so I can't guarantee this code will run without error., but you will get the drift.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Hope this helps. J

  6. #6
    Forum Contributor
    Join Date
    08-06-2007
    Posts
    105

    Re: Auto Save - VBA Code or Excel option?

    Thanks!!!!

  7. #7
    Registered User
    Join Date
    02-02-2011
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Auto Save - VBA Code or Excel option?

    Quote Originally Posted by jaslake View Post
    I put some notes in the code so you can see what it's doing. I made these notes in NotePad so I can't guarantee this code will run without error., but you will get the drift.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Hope this helps. J


    Hi Sir/Maam,

    I'm still new with creating VBA's and I would like to ask why this script is not working for me... I have an excel file which updates thru web query and publish it on a web page... unfortunately it wouldnt publish unless the master file is saved.... what script can I use to autosave it every 1 minute? please help need it on my work... Thanks in advance

  8. #8
    Registered User
    Join Date
    03-19-2012
    Location
    Brisbane
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: Auto Save - VBA Code or Excel option?

    HI,
    Hope you still get the updates for this thread...
    I found and used the code suplied above, but when I run it I get the error msg:
    "Connot run the macrö "drive/file.xlsm'!SaveBook'. The macro might not be in this workbook or all macros may be disabled."

    I am quite sure sure I enabled the macros, but I am fairly new to them, so if you could run through all possible reasons and solutions for them, that would be great!

    I run Excel 2007 on a Win7 machine, in case that is needed..

    Thanks

  9. #9
    Registered User
    Join Date
    02-19-2012
    Location
    Indiana, USA
    MS-Off Ver
    Excel 2007
    Posts
    24

    Re: Auto Save - VBA Code or Excel option?

    I also got the same error as the last message...

  10. #10
    Registered User
    Join Date
    10-13-2008
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    85

    Re: Auto Save - VBA Code or Excel option?

    Are you sure you have macros enabled in your workbook??
    File --> Options --> Trust Centre --> Trust Centre Settings --> Macro Settings, then choose what settings you need/are allowed to have.

  11. #11
    Registered User
    Join Date
    10-13-2008
    Location
    Australia
    MS-Off Ver
    2007
    Posts
    85

    Re: Auto Save - VBA Code or Excel option?

    Just another note...thanks to all who contributed to this, you have helped me greatly also!

  12. #12
    Registered User
    Join Date
    12-07-2013
    Location
    Application.visible=false
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: Auto Save - VBA Code or Excel option?

    Why re-invent the wheel when excel aulready has a autosave feature?
    in vba:

    Please Login or Register  to view this content.
    if you want to make daily copies of your work, use the application.ontime method shown before and replace thisworkbook.save by this code :

    Please Login or Register  to view this content.
    You will need to make manually a auto_save directory in your workbook's default path or it will trigger an error.
    Also check if you saved it as ".xlsm" or ".xls" and make changes accordingly to the code...

    Also consider to add in your before_close section of thisworkbook (in VBE):

    Please Login or Register  to view this content.
    Last edited by saiya; 12-30-2013 at 06:26 PM.

+ 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