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