Export (0) Print
Expand All
Expand Minimize

Document.SaveAs Method

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 (in microsoft.office.tools.word.dll)

public virtual void SaveAs (
	[OptionalAttribute] ref Object FileName,
	[OptionalAttribute] ref Object FileFormat,
	[OptionalAttribute] ref Object LockComments,
	[OptionalAttribute] ref Object Password,
	[OptionalAttribute] ref Object AddToRecentFiles,
	[OptionalAttribute] ref Object WritePassword,
	[OptionalAttribute] ref Object ReadOnlyRecommended,
	[OptionalAttribute] ref Object EmbedTrueTypeFonts,
	[OptionalAttribute] ref Object SaveNativePictureFormat,
	[OptionalAttribute] ref Object SaveFormsData,
	[OptionalAttribute] ref Object SaveAsAOCELetter,
	[OptionalAttribute] ref Object Encoding,
	[OptionalAttribute] ref Object InsertLineBreaks,
	[OptionalAttribute] ref Object AllowSubstitutions,
	[OptionalAttribute] ref Object LineEnding,
	[OptionalAttribute] ref Object AddBiDiMarks
)

Parameters

FileName

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

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

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

Password

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

AddToRecentFiles

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

WritePassword

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

ReadOnlyRecommended

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

EmbedTrueTypeFonts

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

SaveNativePictureFormat

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

SaveFormsData

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

SaveAsAOCELetter

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

Encoding

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

InsertLineBreaks

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

AllowSubstitutions

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

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

AddBiDiMarks

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

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 Understanding Optional Parameters in COM Interop.

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

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);
    }
}

Show:
© 2014 Microsoft