To set Word to save automatically by using VBA code

Source: Internet
Author: User

Sometimes, when using Word for text editing, suddenly encountered power, or computer automatic shutdown, crash, and other failures, resulting in the work of hard to do out of all the results, is a lot of netizens are very crazy things. Today, I'm going to teach you. Use VBA code to automate backup so that Word can be automatically backed up every few minutes without affecting the file being edited. Let's get to know each other now!

1, open the Word File VBA editor, shortcut key alt+f11, right click on "ThisDocument"-"Insert module";

To set Word to save automatically by using VBA code

2, double click "Module 1" just inserted, add the following code:

Sub Automatic Backup ()

Dim NewTime

NewTime = Now + timevalue ("00:05:10")

Dim mypath$, myname$

MyPath = Activedocument.path

MyName = left$ (ActiveDocument.Name, Len (ActiveDocument.Name)-4)

ChangeFileOpenDirectory MyPath

Activedocument.saveas Filename:=myname & "_temp.doc", readonlyrecommended:=true

Activedocument.saveas Filename:=myname & ". Doc", Readonlyrecommended:=false

Application.ontime newtime, "Automatic backup"

CreateObject ("Wscript.Shell"). Popup "Backup succeeded, backup file name:" & myname & "_temp.doc", 2, "Hint! automatically shut down in 2 seconds!"

End Sub

To set Word to save automatically by using VBA code

To set Word to save automatically by using VBA code

3, double-click "ThisDocument" and add the following code in it:

Private Sub Document_Open ()

Call Automatic backup

End Sub

To set Word to save automatically by using VBA code

4, the default automatic backup time is 5min, if you want to adjust, please modify the "Module 1" in a code: as shown in the red box:

The time format is: HH:MM:SS

To set Word to save automatically by using VBA code

5, save the code and file, and close Word and reopen, reopen click "Options"-"Enable this content", as shown in the figure:

To set Word to save automatically by using VBA code

6, the default backup file name is: "Original filename _temp,lee.doc" and read-only, prompted the dialog box 2s automatic shutdown. The backup effect appears as follows:

To set Word to save automatically by using VBA code

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.