+ Reply to Thread
Results 1 to 5 of 5

AutoSave with New File Name xls 2003

Hybrid View

  1. #1
    Registered User
    Join Date
    01-10-2009
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    3

    AutoSave with New File Name xls 2003

    I've seen past posts that discuss saving to specific locations, or saving with a new file name that adds the date.

    I'm working with a file that I'd like to back up every x minutes. It may be 5 mins, it may be 30 - not sure. I thought there was an addin floating around that would do the following:

    1. AutoSave (not save AutoRecover info) a document with no prompt confirming save.
    2. Change a specific component of the file name:
    -I save my files as "Main File Description 1-10-08 v1.xls". I want the addin to change just the v1 part. Every time the file saves, it will save a new version. So, if I open v1, in 10 minutes (for example), it will save (creating a new file) v2. After 20 minutes of being open, it saves v3. And so on. It would automatically adjust the date as well, so if I am working overnight, it would go from ...1-10-08 v23 to ...1-11-08 v1.

    I don't want to come across as asking for someone to write this for me in vba, etc - I thought that I had seen this online before and couldn't find it when trying to search for it yesterday. If you know where it is, I'd appreciate the direction.

    And if you're one of those types who likes a challenge and is of a particularly generous nature, and you want to write this - I won't complain.

    Thanks

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Welcome to the forum.

    In the ThisWorkbook module:
    Option Explicit
    
    Private Sub Workbook_Open()
        Dim iPos As Long
        Dim sRev As String
        
        On Error Resume Next
        dtInt = Replace(ThisWorkbook.Names("SaveInterval").Value, "=", "") / 1440
        If Err <> 0 Then Exit Sub
        On Error GoTo 0
        
        ' find the v and number following
        sName = Me.FullName
        iPos = InStrRev(sName, "v", , vbTextCompare)
        sRev = Mid(sName, iPos + 1, InStr(1, sName, ".") - 1)
        sExt = Mid(sName, InStrRev(sName, "."))
        sRev = Replace(sRev, sExt, "")
        If Not IsNumeric(sRev) Then Exit Sub
        
        ' get current revision & shorten name
        iRev = sRev
        sName = Left(sName, iPos)
        
        ' schedule macro
        dtSave = Now() + dtInt
        Application.OnTime dtSave, "AutoSave"
    End Sub
    
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        Application.OnTime dtSave, "AutoSave", , False
    End Sub
    In a code module:
    Option Explicit
    
    Public dtSave   As Date     ' next scheduled save
    Public dtInt    As Date     ' save interval
    Public iRev     As Long     ' current revision
    Public sName    As String   ' file name through the "v"
    Public sExt     As String   ' file extension (e.g., ".xls", ".xlsm")
    
    Sub AutoSave()
        iRev = iRev + 1
        ThisWorkbook.SaveAs Filename:=sName & CStr(iRev) & sExt, _
                            AddToMRU:=True
        dtSave = dtSave + dtInt
        Application.OnTime dtSave, "AutoSave"
    End Sub
    You need to create a named constant SaveInterval, e.g.,

    Insert > Name > Define SaveInterval Refers to =30

    The workbook name must be like "*v#.*, i.e., a root name, the letter v, a number (any number of digits), and an extension.
    Last edited by shg; 01-10-2009 at 03:48 PM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    01-10-2009
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    3

    Thumbs up

    Excellent! Thanks - will give this a shot and follow up.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    If that sorts it, would you please mark the thread as Solved?

    Click the Edit button on your first post in the thread

    Click Go Advanced, select [SOLVED] from the Prefix dropdown, then click Save Changes

    (If more than two days have elapsed since your first post, you need to ask a moderator to mark it.)

  5. #5
    Registered User
    Join Date
    01-10-2009
    Location
    Arizona, USA
    MS-Off Ver
    Excel 2003, 2007
    Posts
    3
    alright, may have done this wrong - I inserted the code into the "ThisWorkbook" page under "Microsoft Excel Objects."

    Then I did Insert>Module and pasted the second code in that. Then clicked save.

    Went back to the excel file and clicked Insert>Name>Define> and typed in SaveInterval - which changed the name of cell A1 (the highlighted cell) to SaveInterval. I then entered into that cell =5.

    I would suspect that after 5 minutes, I would have a second file where my first one was saved, with the v# changed. Did I put the code in the wrong spot in the VBA editor?

+ 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