DocumentBase.SaveAs2 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. This method can be used only in Word 2010 projects.
Namespace: Microsoft.Office.Tools.Word
Assembly: Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)
Syntax
'Declaration
Public Sub SaveAs2 ( _
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, _
ByRef compatibilityMode As Object _
)
public void SaveAs2(
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,
ref Object compatibilityMode
)
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 T:Microsoft.Office.Interop.Word.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.
- compatibilityMode
Type: System.Object%
One of the Microsoft.Office.Interop.Word.WdCompatibilityMode values that specifies the compatibility mode that Word 2010 uses when opening the document.
Exceptions
Exception | Condition |
---|---|
MissingMemberException | This property is used in a Word 2007 project. |
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.
Note
This method appears in IntelliSense in Word 2007 projects that target the .NET Framework 4. However, this property cannot be used in Word 2007 projects.
Optional Parameters
For information on optional parameters, see 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. To use this example, run it from the ThisDocument class in a document-level project.
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
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.