Word 2007怎么利用VBA代码设置自动另存备份文件?
时间:2023-11-23 12:06:22
Word 2007怎么利用VBA代码设置自动另存备份文件?在Word的编辑过程中,Word虽然有自带的自动保存功能,但在工作中常遇到Word突然崩溃或损坏,使文件无法打开,但是我们可以用vba备份,下面分享教程
在Word的编辑过程中,Word虽然有自带的自动保存功能,但在工作中常遇到Word突然崩溃或损坏,使文件无法打开,之前的工作付之一炬,如没有备份文件只能从头开始。 利用VBA代码,实现自动备份功能,不需要认为的操作,使Word每隔几分钟可以自动备份,而不影响正在编辑的文件。
1、打开Word文件的 VBA编辑器,快捷键 Alt+F11,右击【ThisDocument】-> 【插入模块】
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
3、双击【ThisDocument】并在其中 添加如下代码,如图所示:
复制内容到剪贴板
Private Sub Document_Open()
Call 自动备份
End Sub
4、默认自动备份时间为5min,如要调整请修改【模块1】中一句代码:如图中红框所示:
时间格式为:HH : mm : ss
5、保存代码及文件,且关闭word并重新打开,重新打开点击【选项】-> 【启用此内容】,如图:
6、默认备份文件名为:【原文件名_temp,Lee.doc】且为只读,提示对话框2s后自动关闭。备份效果显示如下:
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
如何批量修改Windows 7中文件属性
闪退报错怎么办?重装Win10应用商店程序的两种方法
![](https://img.aspxhome.com/file/2023/28/a243332_0s.jpg)
电脑版wps文档如何将页眉图片向右旋转90度
![](https://img.aspxhome.com/file/2023/2/a182782_0s.png)
Wps怎么删除空白页
![](https://img.aspxhome.com/file/2023/4/a182064_0s.jpg)
怎么设置wps行间距?在哪设置?
![](https://img.aspxhome.com/file/2023/1/a167011_0s.jpg)
win8系统360安全卫士无法启动的解决方法
![](https://img.aspxhome.com/file/2023/4/a304426_0s.jpg)
一步一步教你巧用WPS文字轻松实现论文排版
在word中如何加宽表格的线宽 ?
![](https://img.aspxhome.com/file/2023/2/18912_0s.png)
Excel 如何处理时间数据,容易出现误差的地方
![](https://img.aspxhome.com/file/2023/8/a141318_0s.jpg)
XP设备管理器无法打开并提示找不到mmc怎么解决
![](https://img.aspxhome.com/file/2023/3/a294859_0s.jpg)
excel 如何设置自动保存工作簿
![](https://img.aspxhome.com/file/2023/2/a154862_0s.jpg)
如何在Win11中设置自动登录?Win11开启、禁用自动登录方法
![](https://img.aspxhome.com/file/2023/27/a237036_0s.png)
Win11 22000.132更新失败解决方法
![](https://img.aspxhome.com/file/2023/1/a280541_0s.jpg)
禁止修改win7系统桌面壁纸的方法
![](https://img.aspxhome.com/file/2023/29/a255288_0s.jpg)
word多级编号一和1怎么互换
用WPS表格制作个人简历的方法步骤图
Excel中表格进行分页显示的设置技巧
戴尔vostro笔记本怎样进入bios设置u盘启动?
![](https://img.aspxhome.com/file/2023/6/a323058_0s.jpg)
Win10底部任务栏无响应重启无效怎么处理?
![](https://img.aspxhome.com/file/2023/1/a274845_0s.jpg)
win10系统硬盘ntfs写保护怎么修复
![](https://img.aspxhome.com/file/2023/3/a302439_0s.jpg)