How to use VBA code to implement automatic daily backup of Excel documents

Source: Internet
Author: User
Tags backup

How to use VBA code to implement automatic daily backup of Excel documents

To achieve this "tall yet" features existing Excel features cannot be completed, but also the method of VBA programming. Of course, as you do not understand the VBA code, just follow the steps below to copy and paste.

Step 1th: Open the Excel file you want to back up, right-click on the worksheet tab, and click "View Code".

The 2nd step is to open a VisualBasic window, double-click the ThisWorkbook in the Project window, and paste the following code into the right-hand window.

Code:

Private Sub workbook_beforeclose (Cancel as Boolean)

On Error Resume Next

Dim MyPath As String, fname as String

fname = Format (Date, "YYMMDD") & Thisworkbook.name

MyPath = Thisworkbook.path & "/Backup/"

Thisworkbook.savecopyas MyPath & fname

End Sub

3rd Step: Click the Save command in the Visual Basic window to pop up the prompt to save the macros, and then click the "No" button.

In the Save window that pops up, choose Save Workbook with Excel enabled macros.

4th step: In the current folder, create a new folder named Backup.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.