我目前正在修改Microsoft Word文档以提示用户在保存时执行某些操作。
在他们选择答案后,我想将文档保存为不同的文件类型,将其专门从.docm转换为.docx文件。
Sub FileSave()
Dim myQ As Integer
With ActiveDocument
myQ = MsgBox("Is this the Final version of this document? Clicking 'Yes' will permanently disable macros for moving issues and remove the blank final page.", vbQuestion + vbYesNo)
If myQ = vbYes Then
.SaveAs2 ActiveDocument.Name & ".docx"
DeleteFinalPage
Else
.SaveAs2 ActiveDocument.Name
End If
End With
End Sub
如您所见,这会将文档保存为“DocumentNameHere.docm.docx”
我究竟如何摆脱文件名中令人讨厌的.docm?
答案 0 :(得分:2)
请勿使用文件扩展名来指明文件类型。不要使用固定数量的字符来删除扩展名 - 对于老式的.doc(而不是.docm),这将失败。使用InStrRev。这是为这样的事情而设计的。
关闭扩展名,然后使用专门用于此目的的参数保存为所需类型:FileFormat。
doc.SaveAs2 Left(doc.Name, InStrRev(doc.Name, ".") - 1), wdSaveFormat.wdFormatXMLDocument
答案 1 :(得分:0)
要摆脱.docm我会做的
.saveAs2 left(ActiveDocument.Name,len(ActiveDocument.Name)-5)
这将取消ActiveDocument.Name
的最后5个字符,只留下文档名称而不是扩展名。