Consulting

Results 1 to 5 of 5

Thread: backup of file with date

  1. #1
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location

    backup of file with date

    Hi, I have the following which will save a backup of my file in a specified folder. But I need to add a date with time like now() into it so every time it saves it save with adding in the time with the filename so I can retrieve a backup 3 min ago for instance.

    Any suggestions on this?

    Sub backup()
     On Error Resume Next
        Fname = ActiveWorkbook.Name
        ActiveWorkbook.SaveCopyAs ThisWorkbook.Sheets(".").Range("A41") & "BACKUP OF " & Fname
    ActiveWorkbook.Save
    End Sub
    Thanks in advance.
    Last edited by Aussiebear; 04-27-2023 at 01:05 PM. Reason: Adjusted the code tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Sub backup()
        On Error Resume Next
        Fname = ActiveWorkbook.Name
        ActiveWorkbook.SaveCopyAs ThisWorkbook.Sheets(".").Range("A41") & _
                                  Format(Now, "yyyy-mm-dd hh:mm:ss") & "BACKUP OF " & Fname
        ActiveWorkbook.Save
    End Sub
    Last edited by Aussiebear; 04-27-2023 at 01:06 PM. Reason: Adjusted the code tags
    ____________________________________________
    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 Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    & Format(Now, "HH:MM:SS")
    Last edited by Aussiebear; 04-27-2023 at 01:07 PM. Reason: Adjusted the code tags
    ------------------------------------------------
    Happy Coding my friends

  4. #4
    VBAX Tutor
    Joined
    Jul 2010
    Posts
    225
    Location
    I have tried both ways but it doesnt seem to work.

    If I take away the colon between the time portion it works like 12 00 00 as eg.

    I seems like the format issue it the colons between the hh:mm:ss for some reason...

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You are absolutely right, : is an invalid character in a filename. I should have spotted that.
    ____________________________________________
    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

Posting Permissions

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