Consulting

Results 1 to 3 of 3

Thread: How to back up excel file at regular interval?

  1. #1

    How to back up excel file at regular interval?

    Dear all, I have an excel file which I am working on currently and it is saved in c: drive (say). Now I want to create a backup mechanism which should be run once a particular time each day and backup the latest updated copy and that backup-ed file should be placed in some other location.

    I want to do that as I am constantly modifying that file, have a fear may be in last session I might have done something wrong and therefore should be able to get the most recent back copy, which is not older than 1 day.

    Is there any way to do that? I would be really grateful I somebody point me any help on this.

    Thanks for your time.

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    There really is no in-built way to do this. There is a native AutoRecovery feature, but it doesn't save a copy of the file, but is only there if the file crashes. For an actual autosave feature, you'll need VBA for that. Here are a couple of links which might help:

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=265

    http://www.oaltd.co.uk/MVP/Default.htm (I believe the last supported version is 2003, so don't know if it works on anything beyond that)

  3. #3
    I found a brilliant piece of code on this site a while ago, and whilst it doesn't save automatically at a certain time, it does save a copy elsewhere whenever you press the save button, and it also works if the file is on a shared drive and other people save as well (of course the autosave destination would also have to be shared).

    Private Sub workbook_beforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim sFile
    Dim location As String
    Application.EnableEvents = False
    location = "C:\Desktop\Archive\" 'change to suit
    sFile = Replace(ThisWorkbook.Name, ".xls", " Backup ") & Format(Now, "yyyymmdd hh-mm-ss")
    ThisWorkbook.SaveCopyAs location & sFile & ".xls"
    Application.EnableEvents = True
    End Sub
    Last edited by Aussiebear; 12-20-2022 at 12:19 PM. Reason: Edited code tags

Posting Permissions

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