Word VBA SaveAs错误:不兼容的文件类型和文件扩展名

时间:2016-08-26 12:48:28

标签: vba ms-word word-vba

我正在尝试进行保存 - 与Word 2016中的以下代码一样:

Dim doc As Word.Document
Dim fpFile as string

Set doc = ActiveDocument
fpFile = doc.Path & "\" & doc.Name

doc.SaveAs Filename:=Left(fpFile, Len(fpFile) - 4) & "docx", FileFormat:=wdFormatDocument 

使用Left和Len函数的My Filename参数求值为:

C:\ Users \ My Name \ Documents \ My Company \ My Client \ test folder \ HeaderTemplate.docx

这对我来说很好,但我在SaveAs行上收到错误6294:'不兼容的文件类型和文件扩展名'。

我已经尝试将Filename首先放入字符串变量,我尝试了SaveAs2方法,两者都有相同的结果。我确实想要保存为标准的非启用宏的docx文件。

有什么想法吗?

感谢。

1 个答案:

答案 0 :(得分:11)

wdFormatDocument.doc

wdFormatXMLDocument.docx

From MSDN(适用于Office 2007):

Name                         Value Description
wdFormatDocument                 0 Microsoft Office Word format.
wdFormatDOSText                  4 Microsoft DOS text format.
wdFormatDOSTextLineBreaks        5 Microsoft DOS text with line breaks preserved.
wdFormatEncodedText              7 Encoded text format.
wdFormatFilteredHTML            10 Filtered HTML format.
wdFormatHTML                     8  Standard HTML format.
wdFormatRTF                      6 Rich text format (RTF).
wdFormatTemplate                 1 Word template format.
wdFormatText                     2 Microsoft Windows text format.
wdFormatTextLineBreaks           3 Windows text format with line breaks preserved.
wdFormatUnicodeText              7 Unicode text format.
wdFormatWebArchive               9 Web archive format.
wdFormatXML                     11 Extensible Markup Language (XML) format.
wdFormatDocument97               0 Microsoft Word 97 document format.
wdFormatDocumentDefault         16 Word default document file format. For Microsoft Office Word 2007, this is the DOCX format.
wdFormatPDF                     17 PDF format.
wdFormatTemplate97               1 Word 97 template format.
wdFormatXMLDocument             12 XML document format.
wdFormatXMLDocumentMacroEnabled 13 XML document format with macros enabled.
wdFormatXMLTemplate             14 XML template format.
wdFormatXMLTemplateMacroEnabled 15 XML template format with macros enabled.
wdFormatXPS                     18 XPS format.