Word中用VBA代码设置自动保存的操作方法
时间:2023-04-05 16:37:54
有时候,在使用Word进行文字编辑的时候,突然遇到断电,或者电脑自动关机、死机等故障的时候,导致辛辛苦苦做出来的劳动成果全部泡汤,是很多网友都非常抓狂的事情。如何利用VBA代码,实现自动备份功能,使Word每隔几分钟可以自动备份,而不影响正在编辑的文件。今天,小编就教大家在Word中用VBA代码设置自动保存的操作方法。
Word中用VBA代码设置自动保存的操作步骤:
1、打开Word文件的 VBA编辑器,快捷键 Alt+F11,右击【ThisDocument】-》 【插入模块】;
用VBA代码设置Word自动保存的步骤
2、双击刚才插入的【模块1】,添加如下代码:
Sub 自动备份()
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, “自动备份”
CreateObject(“Wscript.shell”).popup “备份成功,备份文件名为:” & myName & “_temp.doc”, 2, “提示!2秒后自动关闭!”
End Sub
用VBA代码设置Word自动保存的步骤
用VBA代码设置Word自动保存的步骤
3、双击【ThisDocument】并在其中 添加如下代码:
Private Sub Document_Open()
Call 自动备份
End Sub
用VBA代码设置Word自动保存的步骤
4、默认自动备份时间为5min,如要调整请修改【模块1】中一句代码:如图中红框所示:
时间格式为:HH : mm : ss
用VBA代码设置Word自动保存的步骤
5、保存代码及文件,且关闭word并重新打开,重新打开点击【选项】-》 【启用此内容】,如图:
用VBA代码设置Word自动保存的步骤
6、默认备份文件名为:【原文件名_temp,Lee.doc】且为只读,提示对话框2s后自动关闭。备份效果显示如下:
用VBA代码设置Word自动保存的步骤
Word中用VBA代码设置自动保存的操作
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Win8.1中怎样在文件资源管理器中搜索文件
![](https://img.aspxhome.com/file/2023/29/a255664_0s.jpg)
MAC下误删了储存资料怎么办?
![](https://img.aspxhome.com/file/2023/1/a216051_0s.jpg)
win11usb共享网络电脑没反应的两种解决方法!
![](https://img.aspxhome.com/file/2023/30/a269671_0s.png)
6种方法找回谷歌浏览器不见了的工具栏
![](https://img.aspxhome.com/file/2023/30/a265332_0s.jpg)
Picture Manager怎么调整图片尺寸?
Win10如何连接网络?Win10 10041版本连接网络的方法
![](https://img.aspxhome.com/file/2023/2/a291834_0s.jpg)
Win10电脑设置图片解锁的方法?
![](https://img.aspxhome.com/file/2023/4/a303201_0s.png)
Win10专业版如何修改帐户名称?Win10专业版修改帐户名称的方法
![](https://img.aspxhome.com/file/2023/26/a223260_0s.png)
教你如何在Windows10上将PDF转换为JPG
![](https://img.aspxhome.com/file/2023/26/a219888_0s.png)
Win10怎么自由同步?Win10自由控制同步内容方法
![](https://img.aspxhome.com/file/2023/9/51669_0s.jpg)
Win7怎么恢复出厂设置?Win7恢复出厂操作方法分享
![](https://img.aspxhome.com/file/2023/1/a276539_0s.png)
在word中怎么去除文本边框?
![](https://img.aspxhome.com/file/2023/1/28631_0s.jpg)
怎么在iOS版WPS共享播放
使命召唤六大游戏模式介绍
![](https://img.aspxhome.com/file/2023/7/a329132_0s.jpg)
Win10升级KB3122947后报错80070643怎么办?
![](https://img.aspxhome.com/file/2023/26/a226432_0s.jpg)
电脑C盘中的哪些文件可以删除?C盘清理垃圾文件方法
Word 2010 灵活使用“通配符”精确查找word表格中的字句
![](https://img.aspxhome.com/file/2023/8/24848_0s.jpg)
Win10系统兼容Win7软件的设置方法
![](https://img.aspxhome.com/file/2023/1/a279806_0s.png)
leapftp怎么用?leapftp使用教程
![](https://img.aspxhome.com/file/2023/1/a272376_0s.png)
CAD如何创建新图层?AutoCAD2008新建图层步骤分享
![](https://img.aspxhome.com/file/2023/7/a331250_0s.jpg)