Document.SaveAs Method (2007 System)

Saves the document with a new name or format. Some of the arguments for this method correspond to the options in the Save As dialog box.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)

Syntax

'Declaration
Public Sub SaveAs ( _
    ByRef FileName As Object, _
    ByRef FileFormat As Object, _
    ByRef LockComments As Object, _
    ByRef Password As Object, _
    ByRef AddToRecentFiles As Object, _
    ByRef WritePassword As Object, _
    ByRef ReadOnlyRecommended As Object, _
    ByRef EmbedTrueTypeFonts As Object, _
    ByRef SaveNativePictureFormat As Object, _
    ByRef SaveFormsData As Object, _
    ByRef SaveAsAOCELetter As Object, _
    ByRef Encoding As Object, _
    ByRef InsertLineBreaks As Object, _
    ByRef AllowSubstitutions As Object, _
    ByRef LineEnding As Object, _
    ByRef AddBiDiMarks As Object _
)
'Usage
Dim instance As Document 
Dim FileName As Object 
Dim FileFormat As Object 
Dim LockComments As Object 
Dim Password As Object 
Dim AddToRecentFiles As Object 
Dim WritePassword As Object 
Dim ReadOnlyRecommended As Object 
Dim EmbedTrueTypeFonts As Object 
Dim SaveNativePictureFormat As Object 
Dim SaveFormsData As Object 
Dim SaveAsAOCELetter As Object 
Dim Encoding As Object 
Dim InsertLineBreaks As Object 
Dim AllowSubstitutions As Object 
Dim LineEnding As Object 
Dim AddBiDiMarks As Object

instance.SaveAs(FileName, FileFormat, _
    LockComments, Password, AddToRecentFiles, _
    WritePassword, ReadOnlyRecommended, _
    EmbedTrueTypeFonts, SaveNativePictureFormat, _
    SaveFormsData, SaveAsAOCELetter, _
    Encoding, InsertLineBreaks, AllowSubstitutions, _
    LineEnding, AddBiDiMarks)
public void SaveAs(
    ref Object FileName,
    ref Object FileFormat,
    ref Object LockComments,
    ref Object Password,
    ref Object AddToRecentFiles,
    ref Object WritePassword,
    ref Object ReadOnlyRecommended,
    ref Object EmbedTrueTypeFonts,
    ref Object SaveNativePictureFormat,
    ref Object SaveFormsData,
    ref Object SaveAsAOCELetter,
    ref Object Encoding,
    ref Object InsertLineBreaks,
    ref Object AllowSubstitutions,
    ref Object LineEnding,
    ref Object AddBiDiMarks
)
public:
void SaveAs(
    Object^% FileName, 
    Object^% FileFormat, 
    Object^% LockComments, 
    Object^% Password, 
    Object^% AddToRecentFiles, 
    Object^% WritePassword, 
    Object^% ReadOnlyRecommended, 
    Object^% EmbedTrueTypeFonts, 
    Object^% SaveNativePictureFormat, 
    Object^% SaveFormsData, 
    Object^% SaveAsAOCELetter, 
    Object^% Encoding, 
    Object^% InsertLineBreaks, 
    Object^% AllowSubstitutions, 
    Object^% LineEnding, 
    Object^% AddBiDiMarks
)
public function SaveAs(
    FileName : Object, 
    FileFormat : Object, 
    LockComments : Object, 
    Password : Object, 
    AddToRecentFiles : Object, 
    WritePassword : Object, 
    ReadOnlyRecommended : Object, 
    EmbedTrueTypeFonts : Object, 
    SaveNativePictureFormat : Object, 
    SaveFormsData : Object, 
    SaveAsAOCELetter : Object, 
    Encoding : Object, 
    InsertLineBreaks : Object, 
    AllowSubstitutions : Object, 
    LineEnding : Object, 
    AddBiDiMarks : Object
)

Parameters

  • FileName
    Type: System.Object%

    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.

  • FileFormat
    Type: System.Object%

    The format in which the document is saved. Can be any WdSaveFormat value. To save a document in another format, specify the appropriate value for the SaveFormat property.

  • LockComments
    Type: System.Object%

    true to lock the document for comments. The default is false.

  • Password
    Type: System.Object%

    A password string for opening the document. (See Remarks below.)

  • AddToRecentFiles
    Type: System.Object%

    true to add the document to the list of recently used files on the File menu. The default is true.

  • WritePassword
    Type: System.Object%

    A password string for saving changes to the document. (See Remarks below.)

  • ReadOnlyRecommended
    Type: System.Object%

    true to have Microsoft Office Word suggest read-only status whenever the document is opened. The default is false.

  • EmbedTrueTypeFonts
    Type: System.Object%

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

  • SaveNativePictureFormat
    Type: System.Object%

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

  • SaveFormsData
    Type: System.Object%

    true to save the data entered by a user in a form as a data record.

  • SaveAsAOCELetter
    Type: System.Object%

    If the document has an attached mailer, true to save the document as an AOCE letter (the mailer is saved).

  • Encoding
    Type: System.Object%

    MsoEncoding. The code page, or character set, to use for documents saved as encoded text files. The default is the system code page.

  • InsertLineBreaks
    Type: System.Object%

    If the document is saved as a text file, true to insert line breaks at the end of each line of text.

  • AllowSubstitutions
    Type: System.Object%

    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.

  • LineEnding
    Type: System.Object%

    The way Word marks the line and paragraph breaks in documents saved as text files. Can be any WdLineEndingType value.

  • AddBiDiMarks
    Type: System.Object%

    true adds control characters to the output file to preserve bi-directional layout of the text in the original document.

Remarks

Avoid using hard-coded passwords in your applications. If a password is required in a procedure, request the password from the user, store it in a variable, and then use the variable in your code.

Optional Parameters

For information on optional parameters, see The Variable missing and Optional Parameters in Office Solutions.

Examples

The following code example uses the SaveAs method to save the document in RTF format using the new file name myfile.doc.

This example is for a document-level customization.

Private Sub DocumentSaveAs()

    Me.SaveAs(FileName:="myfile.doc", FileFormat:=Word.WdSaveFormat.wdFormatRTF, _
        LockComments:=False, AddToRecentFiles:=True, ReadOnlyRecommended:=False, _
        EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=True, _
        SaveFormsData:=True, SaveAsAOCELetter:=False, _
        Encoding:=Office.MsoEncoding.msoEncodingUSASCII, _
        InsertLineBreaks:=False, AllowSubstitutions:=False, _
        LineEnding:=Word.WdLineEndingType.wdCRLF, _
        AddBiDiMarks:=False)
End Sub
private void DocumentSaveAs()
{
    object FileName = "myfile.doc";
    object FileFormat = Word.WdSaveFormat.wdFormatRTF;
    object LockComments = false;
    object AddToRecentFiles = true;
    object ReadOnlyRecommended = false;
    object EmbedTrueTypeFonts = false;
    object SaveNativePictureFormat = true;
    object SaveFormsData = true;
    object SaveAsAOCELetter = false;
    object Encoding = Office.MsoEncoding.msoEncodingUSASCII;
    object InsertLineBreaks = false;
    object AllowSubstitutions = false;
    object LineEnding = Word.WdLineEndingType.wdCRLF;
    object AddBiDiMarks = false;

    if (this.SaveFormat == (int)Word.WdSaveFormat.wdFormatDocument)
    {
        this.SaveAs(ref FileName, ref FileFormat, ref LockComments,
            ref missing, ref AddToRecentFiles, ref missing,
            ref ReadOnlyRecommended, ref EmbedTrueTypeFonts,
            ref SaveNativePictureFormat, ref SaveFormsData,
            ref SaveAsAOCELetter, ref Encoding, ref InsertLineBreaks,
            ref AllowSubstitutions, ref LineEnding, ref AddBiDiMarks);
    }
}

.NET Framework Security

See Also

Reference

Document Class

Document Members

Microsoft.Office.Tools.Word Namespace