+ Reply to Thread
Results 1 to 7 of 7

create copy file when closing excel in VBA

  1. #1
    Registered User
    Join Date
    12-06-2023
    Location
    Minneapolis, MN
    MS-Off Ver
    365
    Posts
    4

    create copy file when closing excel in VBA

    Hi,
    I'm very new to VBA. I was able to find help in making a macro, and linking a button, to make a copy of my file on a different drive.
    Is it possible to do this when I close do have functionality when I close excel?

    Here is my code:
    Sub Backup_Files()
    ActiveWorkbook.SaveCopyAs "D:\Time Sheets\BackUp_" + ActiveWorkbook.Name
    End Sub

  2. #2
    Registered User
    Join Date
    12-06-2023
    Location
    Minneapolis, MN
    MS-Off Ver
    365
    Posts
    4

    Re: create copy file when closing excel in VBA

    Here's a copy of my file. My code is in Module4
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    12-06-2023
    Location
    Minneapolis, MN
    MS-Off Ver
    365
    Posts
    4

    Re: create copy file when closing excel in VBA

    I've been able to figure out my issue.
    I appreciate your time if you've looked into this.

  4. #4
    Registered User
    Join Date
    12-06-2023
    Location
    brussel
    MS-Off Ver
    2013
    Posts
    5

    Re: create copy file when closing excel in VBA

    Would you mind posting your solution? Looking into doing the same thing, but haven't figured it out yet .
    Thanks

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: create copy file when closing excel in VBA


    Hi,

    just using the workbook event BeforeClose …

  6. #6
    Registered User
    Join Date
    12-06-2023
    Location
    Minneapolis, MN
    MS-Off Ver
    365
    Posts
    4

    Re: create copy file when closing excel in VBA

    Code:
    Private Sub Workbook_BeforeClose(Cancel As Boolean) 'Fire when user closes Workbook
    ActiveWorkbook.SaveCopyAs "D:\Time Sheets\BackUp_" + ActiveWorkbook.Name
    End Sub

    Edit what's in bold.

    Make sure your in ThisWorkbook, not a module (see pic).backup_vba.JPG
    Last edited by _Sparky_; 12-06-2023 at 08:41 PM.

  7. #7
    Registered User
    Join Date
    12-06-2023
    Location
    brussel
    MS-Off Ver
    2013
    Posts
    5

    Re: create copy file when closing excel in VBA

    thank you very much

+ 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 100 copy of a excel file with unique name
    By kakero in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-23-2021, 02:36 AM
  2. clean method for closing excel file without leaving a shell or closing other excel files
    By QuantumSquirrel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-14-2020, 08:20 AM
  3. VBA Project not closing after closing Excel file
    By GOGGS in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-29-2016, 10:26 AM
  4. Replies: 3
    Last Post: 10-28-2015, 12:25 PM
  5. Save a copy of current .xlsm file without closing the original
    By gezza07 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-24-2013, 08:52 PM
  6. Replies: 1
    Last Post: 12-23-2012, 03:59 AM
  7. 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

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