+ Reply to Thread
Results 1 to 3 of 3

VBA to create dated backup file

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    12-18-2011
    Location
    long island
    MS-Off Ver
    365
    Posts
    236

    VBA to create dated backup file

    I have this code that is ran from an excel workbook:
    Sub Export_Shift()
    
    ActiveWorkbook.Sheets(1).Select
    ActiveSheet.Copy
     
     
        ActiveWorkbook.SaveAs "S:\Production reports\" & Replace(Range("G3").Value, "/", "-") & "-" & Range("G5").Value, _
            FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
        
        ActiveWindow.Close
    
    End Sub
    Now i want to go a step further and create a backup of an ACCESS file. Say access file "Database" in "C:\Database" i want to have a copy saved in "C:\Backup" with a naming scheme like Replace(Range("G3").Value (Database 03-30-15 for example). If not Replace(Range("G3").Value then just todays date would be fine.

    I know that this isnt directly related to excel, but i want this to happen every time i run the code above in my excel workbook. Is it possible? Thanks

  2. #2
    Registered User
    Join Date
    02-27-2015
    Location
    West
    MS-Off Ver
    2010 Professional
    Posts
    18

    Re: VBA to create dated backup file

    You can add this to the end of your filename, using whatever date format you prefer:

     & Format(Date, "yy_mm_dd")

  3. #3
    Forum Contributor
    Join Date
    12-18-2011
    Location
    long island
    MS-Off Ver
    365
    Posts
    236

    Re: VBA to create dated backup file

    Thank you not quite what im looking to do. Ive come up with this code that simply copies and changes the name:
    FileCopy "S:\Shipping Receiving\Extrusion\dbExtrusion Receiving.mdb", "S:\AC 174 Railing Certification Program\Database Backups\Backup of dbExtrusion Receiving " & Month(Now()) & "-" & Day(Now()) & "-" & Year(Now()) & ".mdb"
    The code gives me an error: Runtime error 70, permission denied. Ive read that this happens when the file is open by other users. I can get around the file being open by other users, is there a different code i can use?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Open multiple dated text files and import dated data specified in file name
    By andygxxxv in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2013, 03:56 PM
  2. Replies: 6
    Last Post: 03-07-2012, 04:56 PM
  3. Create Backup File Within A Macro
    By nebb in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-10-2007, 09:41 AM
  4. [SOLVED] Backup:always create a backup file in the save options
    By Alek in forum Excel General
    Replies: 1
    Last Post: 01-07-2006, 09:25 PM
  5. How do I Create backup of excel file in other folder
    By khalid in forum Excel General
    Replies: 1
    Last Post: 05-24-2005, 06:32 AM

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