Document.SaveAs2 方法 (Word)Document.SaveAs2 method (Word)

使用新的名称或格式保存指定的文档。Saves the specified document with a new name or format. 此方法的一些参数与 “另存为” 对话框(“文件” 选项卡)中的选项相对应。Some of the arguments for this method correspond to the options in the Save As dialog box (File tab).


expressionexpression. SaveAs2( _FileName_ , _FileFormat_ , _LockComments_ , _Password_ , _AddToRecentFiles_ , _WritePassword_ , _ReadOnlyRecommended_ , _EmbedTrueTypeFonts_ , _SaveNativePictureFormat_ , _SaveFormsData_ , _SaveAsAOCELetter_ , _Encoding_ , _InsertLineBreaks_ , _AllowSubstitutions_ , _LineEnding_ , _AddBiDiMarks_ , _CompatibilityMode_ )SaveAs2( _FileName_ , _FileFormat_ , _LockComments_ , _Password_ , _AddToRecentFiles_ , _WritePassword_ , _ReadOnlyRecommended_ , _EmbedTrueTypeFonts_ , _SaveNativePictureFormat_ , _SaveFormsData_ , _SaveAsAOCELetter_ , _Encoding_ , _InsertLineBreaks_ , _AllowSubstitutions_ , _LineEnding_ , _AddBiDiMarks_ , _CompatibilityMode_ )

_表达式_一个返回**Document** 对象的表达式。expression An expression that returns a Document object.


名称Name 必需/可选Required/Optional 数据类型Data type 说明Description
FileNameFileName 可选Optional VariantVariant 文档的名称。The name for the document. 默认值为当前文件夹和文件名。The default is the current folder and file name. 如果从未保存过文档,将使用默认名称(例如,Doc1.doc)。If the document has never been saved, the default name is used (for example, Doc1.doc). 如果已经存在具有指定文件名的文档,则覆盖该文档,并且在覆盖前不提示用户。If a document with the specified file name already exists, the document is overwritten without prompting the user.
FileFormatFileFormat 可选Optional VariantVariant 文档的保存格式。The format in which the document is saved. 可以是任何 WdSaveFormat 常量。Can be any WdSaveFormat constant. 若要以另一种格式保存文档,请为 FileConverter 对象的 SaveFormat 属性指定适当的值。To save a document in another format, specify the appropriate value for the SaveFormat property of the FileConverter object.
LockCommentsLockComments 可选Optional VariantVariant 如果为 True,则锁定文档注释。True to lock the document for comments. 默认值为 FalseThe default is False.
PasswordPassword 可选Optional VariantVariant 用于打开文档的密码字符串。A password string for opening the document. 请参阅下面的"说明")。(See Remarks below.)
AddToRecentFilesAddToRecentFiles 可选Optional VariantVariant 如果为 True,则将文档添加到“文件”**** 菜单上最近使用的文件列表中。True to add the document to the list of recently used files on the File menu. 默认值为 TrueThe default is True.
WritePasswordWritePassword 可选Optional VariantVariant 用于保存文档更改的密码字符串。A password string for saving changes to the document. (请参阅下面的“备注”。)(See Remarks below.)
ReadOnlyRecommendedReadOnlyRecommended 可选Optional VariantVariant 如果为 True,则每次打开文档时,Microsoft Word 都将建议采用只读方式。True to have Microsoft Word suggest read-only status whenever the document is opened. 默认值为 FalseThe default is False.
EmbedTrueTypeFontsEmbedTrueTypeFonts 可选Optional VariantVariant 如果为 True,则 TrueType 字体随文档一起保存。True to save TrueType fonts with the document. 如果省略,则 EmbedTrueTypeFonts 参数将假定为 EmbedTrueTypeFonts 属性的值。If omitted, the EmbedTrueTypeFonts argument assumes the value of the EmbedTrueTypeFonts property.
SaveNativePictureFormatSaveNativePictureFormat 可选Optional VariantVariant 如果为 True,则对于从其他系统平台(如 Macintosh)导入的图形,只保存其 Microsoft Windows 版本。If graphics were imported from another platform (for example, Macintosh), True to save only the Microsoft Windows version of the imported graphics.
SaveFormsDataSaveFormsData 可选Optional VariantVariant 如果为 True,则将用户在窗体中输入的数据保存为记录。True to save the data entered by a user in a form as a record.
SaveAsAOCELetterSaveAsAOCELetter 可选Optional VariantVariant 如果文档包含附加的邮件,当为 True 时,将文档存为 AOCE 信函(同时保存邮件)。If the document has an attached mailer, True to save the document as an AOCE letter (the mailer is saved).
EncodingEncoding 可选Optional VariantVariant 用于另存为编码文本文件的文档的代码页或字符集。The code page, or character set, to use for documents saved as encoded text files. 默认值是系统代码页。The default is the system code page. 不能将所有 MsoEncoding 常量用于此参数。You cannot use all MsoEncoding constants with this parameter.
InsertLineBreaksInsertLineBreaks 可选Optional VariantVariant 在将文档另存为文本文件时,如果为 True,则在每一行文本后插入换行符。If the document is saved as a text file, True to insert line breaks at the end of each line of text.
AllowSubstitutionsAllowSubstitutions 可选Optional VariantVariant 将文档另存为文本文件时,如果为 True,则 Word 可以将一些符号替换为相似的文本。If the document is saved as a text file, True allows Word to replace some symbols with text that looks similar. 例如,将版权符号显示为 (c)。For example, displaying the copyright symbol as (c). 默认值为 FalseThe default is False.
LineEndingLineEnding 可选Optional VariantVariant Word 在另存为文本文件的文档中标记换行符和分段符的方式。The way Word marks the line and paragraph breaks in documents saved as text files. 可以是以下 WdLineEndingType 常量之一:wdCRLF(默认值)或 wdCROnlyCan be one of the following WdLineEndingType constants: wdCRLF (default) or wdCROnly.
AddBiDiMarksAddBiDiMarks 可选Optional VariantVariant 如果为 True,则为输出文件添加控制符,以保留原始文档中文本的双向版式。True adds control characters to the output file to preserve bi-directional layout of the text in the original document.
CompatibilityModeCompatibilityMode 可选Optional VariantVariant 打开文档时,Word 使用的兼容性模式。The compatibility mode that Word uses when opening the document. WdCompatibilityMode 常量。WdCompatibilityMode constant.
默认情况下,如果没有为此参数指定任何值,则 Word 输入值 0,这会指定应保留文档的当前兼容性模式。By default, if no value is specified for this parameter, Word enters a value of 0, which specifies that the current compatibility mode of the document should be retained.

返回值Return value



下面的代码示例将活动文档另存为 Test.rtf,格式为 RTF。The following code example saves the active document as Test.rtf in rich-text format (RTF).

Sub SaveAsRTF() 
    ActiveDocument.SaveAs2 FileName:="Text.rtf", _ 
End Sub

下面的代码示例将活动文档保存为纯文本格式,扩展名为“.txt”。The following code example saves the active document in text-file format with the extension ".txt".

Sub SaveAsTextFile() 
    Dim strDocName As String 
    Dim intPos As Integer 
    ' Find position of extension in file name 
    strDocName = ActiveDocument.Name 
    intPos = InStrRev(strDocName, ".") 
    If intPos = 0 Then 
        ' If the document has not yet been saved 
        ' Ask the user to provide a file name 
        strDocName = InputBox("Please enter the name " & _ 
            "of your document.") 
        ' Strip off extension and add ".txt" extension 
        strDocName = Left(strDocName, intPos - 1) 
        strDocName = strDocName & ".txt" 
    End If 
    ' Save file with new extension 
    ActiveDocument.SaveAs2 FileName:=strDocName, _ 
End Sub

下面的代码示例遍历所有已安装的转换器,如果找到了 WordPerfect 6.0 转换器,则使用转换器保存活动文档。The following code example loops through all the installed converters, and if it finds the WordPerfect 6.0 converter, it saves the active document using the converter.

Sub SaveWithConverter() 
    Dim cnvWrdPrf As FileConverter 
    ' Look for WordPerfect file converter 
    ' And save document using the converter 
    ' For the FileFormat converter value 
    For Each cnvWrdPrf In Application.FileConverters 
        If cnvWrdPrf.ClassName = "WrdPrfctWin" Then 
            ActiveDocument.SaveAs2 FileName:="MyWP.doc", _ 
        End If 
    Next cnvWrdPrf 
End Sub

下面的代码示例演示使用密码保存文档的过程。The following code example shows a procedure that saves a document with a password.

Sub SaveWithPassword(docCurrent As Document, strPWD As String) 
    With docCurrent 
        .SaveAs2 WritePassword:=strPWD 
    End With 
End Sub

另请参阅See also

Document 对象Document Object

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.