如果我在word中打开.mhtml
文件,然后点击"另存为"选项,默认"另存为类型"是.mhtml
。但我需要默认"另存为类型"是.doc/.docx
。有没有办法实现这个目标?
答案 0 :(得分:2)
创建保存事件的处理程序,在此事件中分析原始文档的类型并显示您自己的SaveAs对话框。
详细说明:
<强> 1。处理强>
在普通模板中,创建一个类,例如 clsSaveAs :
Public WithEvents appWord As Word.Application
Private Function IsMime(fileName As String)
Dim mimeTag As String
'open document
Open fileName For Input Access Read As #1
On Error Resume Next
'read beginning of the document
Input #1, mimeTag
On Error GoTo 0
Close #1
'MHTM file starts with "MIME" string
IsMime = Left(mimeTag, 4) = "MIME"
End Function
Private Sub appWord_DocumentBeforeSave _
(ByVal Doc As Document, _
SaveAsUI As Boolean, _
Cancel As Boolean)
'get extension
ar = Split(Doc.Name, ".")
ext = LCase(ar(UBound(ar)))
'what is the document MIME type?
If IsMime(Doc.FullName) Then
'my own saveas dialog
With Application.Dialogs(wdDialogFileSaveAs)
.Format = WdSaveFormat.wdFormatXMLDocument 'docx
.Show
End With
Cancel = True 'cancel saving process
Else
'normal saving
Cancel = False
End If
End Sub
<强> 2。使用处理程序
在普通模板中创建一个新模块:
Dim csa As New clsSaveAs
Sub Register_Event_Save_As_Handler()
Set csa.appWord = Word.Application
End Sub
'autorun for any opening document
'Note: AutoOpen could be only one in normal template
Sub AutoOpen()
'could be run only for mht, mhtm documents, but never mind
Register_Event_Save_As_Handler
End Sub
您需要在MHTML文档中包含此代码。你可以这样做(但我还没试过):
请注意,所有这些工作都是非标准的,你是在冰上行走,小心。
有用的链接:
答案 1 :(得分:0)
引用Office的帮助文档:
1-Click the File tab.
2-Click Options.
3-Click Save.
4-Under Save documents, click "Word 97-2003 Document (*.doc)" or "Word Document (*.docx)" in the Save files in this format.