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并重新打开,重新打开点击【选项】-》 【启用此内容】

以上就是word怎么用VBA命令完成保存退出的全部内容,希望对您有帮助。内容来源于互联网,本站仅做分享以供参考。

热门文章
怎样调整word中表格里的字
word文档中如何更改目录的字体颜色
word文档艺术字棱台在哪设置?
怎样用Word画柱状图?
为什么WORD保存的都是副本状态?
word中插入的图表显示不出来
WORD文档中怎样使题目与答案相链接
WORD文档如何调出纵向标尺
用word插入的表格如何打印成彩色的
word中怎么能将标题向上移动