word怎么用VBA命令完成保存退出
时间:2023-11-11 22:40:10
1、打开Word文件的 VBA编辑器,快捷键 Alt+F11,右击【ThisDocument】-》 【插入模块】;
2、双击刚才插入的【模块1】,添加如下代码:
Private Function SaveAsFile(ByVal fileFormat As String)
Dim strDocName As String
Dim intPos As Integer
'Find position of extension in filename
strDocName = ActiveDocument.Name
intPos = InStrRev(strDocName, ".")
If intPos = 0 Then
'If the document has not yet been saved
'Ask the user to provide a filename
strDocName = InputBox("Please enter the name of your document.")
Else
'Strip off extension
strDocName = Left(strDocName, intPos - 1)
strDocName = strDocName & fileFormat
End If
'Save file with new extension
ActiveDocument.SaveAs fileName:=strDocName, fileFormat:=wdFormatText
'Close active document
ActiveDocument.Close SaveChanges:=wdSaveChanges, OriginalFormat:=wdOriginalDocumentFormat
End Function
3、保存代码及文件,且关闭word并重新打开,重新打开点击【选项】-》 【启用此内容】
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
从容应对多个项目,效率翻倍,Mac自由职业者的真理之剑!
![](https://img.aspxhome.com/file/2023/3/a209683_0s.jpeg)
Wn7系统删除文件提示“你需要来自system的权限”怎么办?
![](https://img.aspxhome.com/file/2023/2/a286564_0s.jpg)
怎么通过母版给WPS演示2013插入相同图片
excel表格数据精度设置的教程
Win10 Mobile/WP8.1优秀专业摄影应用OneShot本周再次更新:修复Bug和优化性能
![](https://img.aspxhome.com/file/2023/28/a246486_0s.jpg)
Windows 10首个功能更新之优化UI 带来全新图标
![](https://img.aspxhome.com/file/2023/28/a247341_0s.gif)
Excel2010中改变回车键移动的方向的功能
![](https://img.aspxhome.com/file/2023/4/43164_0s.jpg)
Win10专业版文件夹访问被拒绝要怎么办?
![](https://img.aspxhome.com/file/2023/26/a223471_0s.png)
制作三维格式的PPT目录的图解教程
Excel快速按所选单元格值进行自动筛选
![](https://img.aspxhome.com/file/2023/8/a156488_0s.jpg)
InDesign 教程「57」,如何创建具有吸引力的边注栏?
![](https://img.aspxhome.com/file/2023/4/a203364_0s.jpeg)
win10系统添加win7桌面小工具教程
![](https://img.aspxhome.com/file/2023/29/a253288_0s.png)
PPT排版教程 PPT字号、字体、行距使用技巧
![](https://img.aspxhome.com/file/2023/10/a351922_0s.jpg)
利用WPS绘图功能给文字加上划线或者下划线
excel 如何利用VLOOKUP函数批量修改单元格
![](https://img.aspxhome.com/file/2023/0/a161920_0s.jpg)
Win10开启预览窗格实现不打开文件预览文件内容(文档、图片)
![](https://img.aspxhome.com/file/2023/30/a262554_0s.png)
如何使用WPS中word设置横向页面?
![](https://img.aspxhome.com/file/2023/8/31428_0s.png)
Wps不连续的数据如何求和?Wps不连续数据求和的方法
![](https://img.aspxhome.com/file/2023/8/a182318_0s.gif)
word2013中怎么输入h上有一横的符号?
![](https://img.aspxhome.com/file/2023/6/30686_0s.jpg)
苹果在官网发布公告:为 iOS 13 和 iPadOS 做好准备
![](https://img.aspxhome.com/file/2023/9/a196999_0s.jpg)