word怎么用VBA命令完成保存退出
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并重新打开,重新打开点击【选项】-》 【启用此内容】
您可能感兴趣的文章
- 03-24word里代码对齐快捷键是什么意思
- 03-24word在兼容模式是什么意思
- 03-24word文档字为什么不能前移
- 03-24word文档为什么不能接受修订
- 03-24word中方正小标宋什么意思
- 03-24word为什么会保存文件错误报告
- 03-24cad图为什么插入不到word中,cad图怎么插到word中
- 03-24word表格内为什么不能另起一行,word表格内怎么另起一行
- 03-24为什么word里插不进去页码,word怎么插页码?
- 03-24为什么wps word页面绿色变不回来


阅读排行
推荐教程
- 07-012025最新office2010永久激活码免费分享,附office 2010激活工具
- 07-01怎么免费获取2025最新office2016专业增强版永久激活密钥/序列号
- 07-01office365怎么永久激活?2025.5最新office,office365序列号推荐
- 06-25office2021年最新永久有效正版激活密钥免费分享
- 06-13Office 2024激活工具,2025年Office2024激活工具及激活密钥分享
- 05-12Microsoft office2019产品激活密钥(100%永久激活)
- 07-01office2021专业增强版2021激活密钥2023密钥永久激活 万能office202
- 06-17经验分享Win11激活密钥怎么获取(win11专业版激活密钥)
- 07-01office 2021激活码/序列号推荐,office2021附激活工具
- 06-25Office2021激活密钥永久最新分享




