gpt4 book ai didi

vba - Word VBA 另存为错误 : incompatible file type and file extension

转载 作者:行者123 更新时间:2023-12-04 22:19:26 26 4
gpt4 key购买 nike

我正在尝试使用 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 函数计算为:

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

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

我试过先把文件名放到一个字符串变量中,我试过 SaveAs2 方法,两者都得到了相同的结果。我确实想保存为标准的非启用宏的 docx 文件。

有任何想法吗?

谢谢。

最佳答案

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.

关于vba - Word VBA 另存为错误 : incompatible file type and file extension,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39166746/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com