全部显示

SaveAs 方法

       

用一个新的文件名或格式来保存指定文档。此方法的参数与“文件”菜单的“另存为”对话框中的选项相对应。

expression.SaveAs(FileName, FileFormat, LockComments, Password, AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts, SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter, Encoding, InsertLineBreaks, AllowSubstitutions, LineEnding, AddBiDiMarks)

expression   必需。该表达式返回一个 Document 对象。

FileName   Variant 类型,可选。文档名称。默认值是当前文件夹和文件名。如果从未保存过此文档,则将使用默认的文件名(例如,文档 1.doc)。如果已有文件名指定的文档,则覆盖此文档,而且在覆盖前不提醒用户。

FileFormat   Variant 类型,可选。文档保存的格式。可以是任意 WdSaveFormat 常量。若要将文档保存为另一种格式,请使用 FileConverter 对象的 SaveFormat 属性指定相应的值。

LockComments   Variant 类型,可选。如果为 True,则锁定文档备注。默认值是 False

Password   Variant 类型,可选。打开文档的密码。

AddToRecentFiles   Variant 类型,可选。如果为 True,则将文档添加至“文件”菜单中最近使用的文件列表中。默认值为 True

WritePassword   Variant 类型,可选。保存对文档的修改所需的密码。

ReadOnlyRecommended   Variant 类型,可选。如果为 True,在每次打开文档时,Microsoft Word 将建议用户采用只读方式。默认值为 False

EmbedTrueTypeFonts   Variant 类型,可选。如果为 True,则将文档与 TrueType 字体一起保存。如果忽略,则 EmbedTrueTypeFonts 参数将假定为 EmbedTrueTypeFonts 属性的值。

SaveNativePictureFormat   Variant 类型,可选。如果为 True,则对于从其他系统平台(例如 Macintosh)导入的图形,将仅保存其 Windows 版本。

SaveFormsData   Variant 类型,可选。如果为 True,则将用户在窗体中输入的数据保存为数据记录。

SaveAsAOCELetter   Variant 类型,可选。如果文档包含附加的邮件,当此属性值为 True 时,将文档存为 AOCE 信函(同时保存邮件)。

Encoding  MsoEncoding,可选。将文档保存为编码文本文件时,所用的代码页或字符集。默认值为系统代码页。

InsertLineBreaks  Variant 类型,可选。在将文档保存为文本文件时,如果为 True,在每一行文本后插入换行符。

AllowSubstitutions  Variant 类型,可选。在将文档保存为文本文件时,如果为 True,使 Word 可以将一些符号替换为相似的文本。例如,将版权符号显示为 (c)。默认值是 False

LineEnding  Variant 类型,可选。Word 在文档中标记换行符和分段符的方式被保存为文本文件。可以是任意 WdLineEndingType 常量。

AddBiDiMarks  Variant 类型,可选。如果为 True,则为输出文件添加控制符,以保留原始文档中文本的双向版式。

示例

本示例将活动文档存为 Test.rtf,格式为 RTF。

Sub SaveAsRTF()
    ActiveDocument.SaveAs FileName:="Text.rtf", _
        FileFormat:=wdFormatRTF
End Sub

本示例将活动文档保存为纯文本格式,文件的扩展名为“.txt”。

Sub SaveAsTextFile()
    Dim strDocName As String
    Dim intPos As Integer

    'Find position of extension in filename
    strDocName = ActiveDocument.Name
    intPos = InStrRev(strDocName, ".")

    If intPos = 0 Then

        'If the document has not yet been saved
        'Ask the user to provide a filename
        strDocName = InputBox("Please enter the name " & _
            "of your document.")
    Else

        'Strip off extension and add ".txt" extension
        strDocName = Left(strDocName, intPos - 1)
        strDocName = strDocName & ".txt"
    End If

    'Save file with new extension
    ActiveDocument.SaveAs FileName:=strDocName, _
        FileFormat:=wdFormatText
End Sub

本示例在安装的转换器中循环,如果发现 WordPerfect 6.0 转换器,本示例会使用该转换器保存活动文档。

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.SaveAs FileName:="MyWP.doc", _
                FileFormat:=cnvWrdPrf.SaveFormat
        End If
    Next cnvWrdPrf

End Sub

本示例使用具有改写权限的密码保存 NewFile.doc,然后关闭该文档。本示例假定打开的文档中有一篇名为 NewFile.doc 的文档。如果没有,Word 会显示一条错误消息。

Sub SaveWithPassword()
    With Documents("NewFile.doc")
        .SaveAs WritePassword:="pass"
        .Close
    End With
End Sub