Click to Rate and Give Feedback
MSDN
MSDN Library
Office Development
Microsoft Office XP
Office XP
Methods
S
 SaveAs Method
Collapse All/Expand All Collapse All
SaveAs Method

Saves the specified document with a new name or format. The arguments for this method correspond to the options in the Save As dialog box (File menu).

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

expression   Required. An expression that returns a Document object.

FileName   Optional Variant. The name for the document. The default is the current folder and file name. 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 the user being prompted first.

LockComments   Optional Variant. True to lock the document for comments. The default is False.

Password   Optional Variant. A password string for opening the document.

AddToRecentFiles   Optional Variant. True to add the document to the list of recently used files on the File menu. The default is True.

WritePassword   Optional Variant. A password string for saving changes to the document.

ReadOnlyRecommended   Optional Variant. True to have Microsoft Word suggest read-only status whenever the document is opened. The default is False.

EmbedTrueTypeFonts   Optional Variant. True to save TrueType fonts with the document. If omitted, the EmbedTrueTypeFonts argument assumes the value of the EmbedTrueTypeFonts property.

SaveNativePictureFormat   Optional Variant. If graphics were imported from another platform (for example, Macintosh), True to save only the Windows version of the imported graphics.

SaveFormsData   Optional Variant. True to save the data entered by a user in a form as a data record.

SaveAsAOCELetter   Optional Variant. If the document has an attached mailer, True to save the document as an AOCE letter (the mailer is saved).

InsertLineBreaks  Optional Variant. If the document is saved as a text file, True to insert line breaks at the end of each line of text.

AllowSubstitutions  Optional Variant. If the document is saved as a text file, True allows Word to replace some symbols with text that looks similar. For example, displaying the copyright symbol as (c). The default is False.

AddBiDiMarks  Optional Variant. True adds control characters to the output file to preserve bi-directional layout of the text in the original document.

Example

This example saves the active document as Test.rtf in rich-text format (RTF).

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

This example saves the active document in text-file format with the file extension ".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

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

End Sub

This example saves NewFile.doc with a write password and then closes the document.  This example assumes that one of the open files is named "NewFile.doc."  If not, Word displays an error message.

Sub SaveWithPassword()
    With Documents("NewFile.doc")
        .SaveAs WritePassword:="pass"
        .Close
    End With
End Sub
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker