+ Reply to Thread
Results 1 to 10 of 10

Create backup via VBA when opening Excel workbook

  1. #1
    Registered User
    Join Date
    02-25-2014
    Location
    VA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Create backup via VBA when opening Excel workbook

    I've cobbled this together from a few different references and it's still not working quite right.

    1) Backup an Excel workbook when it is opened automatically.

    --seems to work with Active.workbook.SaveCopyAs

    2) Prevent the backup workbooks from making copies of themselves if they are opened.

    --Gives an error; seems like the IF statement isn't working.

    3) Also seeking a way to remove the password protection from the original file when a backup is made. The backups do not need to be password protected.

    --I know ActiveWorkbook.SaveAs has an option to set the password to "". However, using the Save.As method renames the original file and saves it to the backup location, which is not what I'm going for. Is there some workaround to make SaveAs work more like SaveCopyAs?


    The backup file path is N:\Receipts\Receipt Tracker Backup\

    My current code:

    Please Login or Register  to view this content.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Create backup via VBA when opening Excel workbook

    Hi, mechengr02,

    for problem 2: you might tryx to check the path of the workbook to be located in the backup folder. If so, Exit the sub, else continue:
    Please Login or Register  to view this content.
    for 3.: AFAIR you would need to open all files in the backup folder and do it in another loop (or use SaveAs and recover the original file thereafter).

    Ciao,
    Hoilger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    02-25-2014
    Location
    VA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Create backup via VBA when opening Excel workbook

    Thanks. I don't know why I didn't think of that; too wrapped around the axle of the way I was trying it. #2 solved.

    Looks like a simple method for the #3 is wishful thinking. I'd rather not have to go in and open every backup. Maybe a method will pop up.

  4. #4
    Registered User
    Join Date
    02-25-2014
    Location
    VA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Create backup via VBA when opening Excel workbook

    Still working on #3 --

    a) I decided to try using SaveAs 2x. Once to save to the backup location with the name Date_OriginalFilename. This saved the open file to the backup location & renames it. I don't want to work in the backup file or location. So then I use SaveAs a second time to save the file back to the original file location under the name OriginalFilename.

    I seem to have trouble on the second SaveAs with attempting to store the original file name and file location as variables. What am I doing wrong?

    b) I want to keep the original file password protected and backups unprotected. How do I retrieve the original password as a variable, store it and reapply it on the second SaveAs?

    The original file path is N:\Receipts\
    The backup file path is N:\Receipts\Backup_Tracker\

    Updated code:
    Please Login or Register  to view this content.

  5. #5
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Create backup via VBA when opening Excel workbook

    Hi, mechengr02,

    KISS - keep it safe and simple. I´m afraid you should know the password in order to get access to the workbook.

    Please Login or Register  to view this content.
    Ciao,
    Holger

  6. #6
    Registered User
    Join Date
    02-25-2014
    Location
    VA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Create backup via VBA when opening Excel workbook

    It still dies on the second SaveAs. I suspect it's because the 1st saveAs puts the open file into the backup folder. Then the second SaveAs cannot get out of it to the original location.

    As for the password, it's my spreadsheet, I created the password. I'd like for the spreadsheet to outlive me. The chances of the next person to inherit this spreadsheet knowing VBA are slim. I don't want to display the password. I just want VBA to temporarily store the password, so that it can reapply the password on the second SaveAs. The next person won't know to go into VBA to edit the password.

    I'm trying to make it seamless and automatic with minimal user input.

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Create backup via VBA when opening Excel workbook

    Hi, mechengr02,

    what Operating System is used and where is the folder for the workbooks located? I tested the code on my local pc with Win8.1, Excel2013 on the built-in HDD in a trusted loaction as path and didn´t face any problems.

    Ciao,
    Holger

  8. #8
    Registered User
    Join Date
    02-25-2014
    Location
    VA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Create backup via VBA when opening Excel workbook

    Windows 7
    Excel 2010
    Network locations
    Original file location N:\Receipts\
    Backup file location N:\Receipts\Backup_Tracker\

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Create backup via VBA when opening Excel workbook

    Hi, mechengr02,

    it might be the network location but I´m afraid I would only be able to test on Monday if I´m back at work,

    Ciao,
    Holger

  10. #10
    Registered User
    Join Date
    02-25-2014
    Location
    VA
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Create backup via VBA when opening Excel workbook

    It saves the first time on the network.
    It just doesn't save the second time. I'm thinking the location and name variables need to be adjusted....somehow.

+ 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. Create backup copy of excel file in VB
    By t3623gl in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-06-2012, 03:57 PM
  2. [SOLVED] How do I create a backup woorkbook in Excel 2003.
    By Sheskaty in forum Excel General
    Replies: 10
    Last Post: 01-31-2006, 08:50 AM
  3. [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
  4. [SOLVED] 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
  5. [SOLVED] 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:06 AM

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