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页眉每页不同设置方法介绍
word 2013-09-16
-
如何解决word表格下一页的文字上不去
word 2017-04-15
-
word文档变成只读模式怎么改
word 2017-04-10
-
编辑word时无法选中文字怎么办
word 2017-04-11
-
word表格不能编辑的原因,怎么解决?
word 2016-07-11