Consulting

Results 1 to 5 of 5

Thread: Incorporating a version number (incremental) in filename

  1. #1
    VBAX Contributor
    Joined
    Apr 2008
    Posts
    136
    Location

    Incorporating a version number (incremental) in filename

    Can anyone help with incorporating a version number in the filename everytime the macro is run- the Master sheet is saved.

    Here is the code im currently using:

    Public Sub Save()
    Dim fname As string
    Sheets("Master").copy
    Format(Date, "dd-mm-yy") + "_" + Format(Time, "hh.mm")+ "xls"
    ActiveWorkbook.saveas Fname:="C:\Saved\" &FName
    MsgBox "Your file has been saved"
    ActiveWorkbook.Close
    End Sub
    Many thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Just use date and time, it will be unique

    Public Sub Save()
    Dim fname As String
    'Sheets("Master").Copy
    fname = Format(Now, "dd-mm-yy_hh.mm.ss") & ".xls"
    ActiveWorkbook.SaveAs Filename:="C:\Saved\" & fname
    MsgBox "Your file has been saved as C:\Saved\" & fname
    ActiveWorkbook.Close
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Contributor
    Joined
    Apr 2008
    Posts
    136
    Location
    A version number is needed , if it can be done. If not I will stick with time. Thanks for the extra bits and editing on the current code.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Okay add this code to ThisWorkbook code module

    Public Sub Save()
        Dim fname As String
        Dim myVersion As Long
    myVersion = 1 ' in case it doesn't already exist
        On Error Resume Next
        myVersion = Evaluate(ThisWorkbook.Names("_Version").RefersTo) + 1
        ThisWorkbook.Names.Add Name:="_Version", RefersTo:="=" & myVersion
        ThisWorkbook.Save
    'Sheets("Master").Copy
    fname = Format(Now, "dd-mm-yy_hh.mm.ss") & " v" & myVersion & ".xls"
    ActiveWorkbook.SaveAs Filename:="C:\Saved\" & fname
        MsgBox "Your file has been saved as C:\Saved\" & fname
        ActiveWorkbook.Close
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Contributor
    Joined
    Apr 2008
    Posts
    136
    Location
    works great thanks vmuch!

Posting Permissions

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