Workbook.SaveAs Method (2007 System)

Saves changes to the workbook in a different file.

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

Syntax

'Declaration
Public Sub SaveAs ( _
    Filename As Object, _
    FileFormat As Object, _
    Password As Object, _
    WriteResPassword As Object, _
    ReadOnlyRecommended As Object, _
    CreateBackup As Object, _
    AccessMode As XlSaveAsAccessMode, _
    ConflictResolution As Object, _
    AddToMru As Object, _
    TextCodepage As Object, _
    TextVisualLayout As Object, _
    Local As Object _
)
'Usage
Dim instance As Workbook 
Dim Filename As Object 
Dim FileFormat As Object 
Dim Password As Object 
Dim WriteResPassword As Object 
Dim ReadOnlyRecommended As Object 
Dim CreateBackup As Object 
Dim AccessMode As XlSaveAsAccessMode 
Dim ConflictResolution As Object 
Dim AddToMru As Object 
Dim TextCodepage As Object 
Dim TextVisualLayout As Object 
Dim Local As Object

instance.SaveAs(Filename, FileFormat, _
    Password, WriteResPassword, ReadOnlyRecommended, _
    CreateBackup, AccessMode, ConflictResolution, _
    AddToMru, TextCodepage, TextVisualLayout, _
    Local)
public void SaveAs(
    Object Filename,
    Object FileFormat,
    Object Password,
    Object WriteResPassword,
    Object ReadOnlyRecommended,
    Object CreateBackup,
    XlSaveAsAccessMode AccessMode,
    Object ConflictResolution,
    Object AddToMru,
    Object TextCodepage,
    Object TextVisualLayout,
    Object Local
)
public:
void SaveAs(
    Object^ Filename, 
    Object^ FileFormat, 
    Object^ Password, 
    Object^ WriteResPassword, 
    Object^ ReadOnlyRecommended, 
    Object^ CreateBackup, 
    XlSaveAsAccessMode AccessMode, 
    Object^ ConflictResolution, 
    Object^ AddToMru, 
    Object^ TextCodepage, 
    Object^ TextVisualLayout, 
    Object^ Local
)
public function SaveAs(
    Filename : Object, 
    FileFormat : Object, 
    Password : Object, 
    WriteResPassword : Object, 
    ReadOnlyRecommended : Object, 
    CreateBackup : Object, 
    AccessMode : XlSaveAsAccessMode, 
    ConflictResolution : Object, 
    AddToMru : Object, 
    TextCodepage : Object, 
    TextVisualLayout : Object, 
    Local : Object
)

Parameters

  • Filename
    Type: System.Object

    The name of the file to be saved. You can include a full path; if you do not, Microsoft Office Excel saves the file in the current folder.

  • FileFormat
    Type: System.Object

    The file format to use when you save the file. For a list of valid choices, see the FileFormat property. For an existing file, the default format is the last file format specified; for a new file, the default is the format of the version of Excel being used.

  • Password
    Type: System.Object

    A case-sensitive string (no more than 15 characters) that indicates the protection password to be given to the file.

  • WriteResPassword
    Type: System.Object

    The write-reservation password for this file. If a file is saved with the password and the password is not supplied when the file is opened, the file is opened as read-only.

  • ReadOnlyRecommended
    Type: System.Object

    true to display a message when the file is opened, recommending that the file be opened as read-only.

  • AddToMru
    Type: System.Object

    true to add this workbook to the list of recently used files. The default value is false.

  • TextCodepage
    Type: System.Object

    Not used in U.S. English Excel.

  • TextVisualLayout
    Type: System.Object

    Not used in U.S. English Excel.

  • Local
    Type: System.Object

    true saves files against the language of Excel (including control panel settings). false (default) saves files against the language of Visual Basic for Applications (VBA).

Remarks

Visual Studio Tools for Office does not support saving a workbook as a shared workbook.

Optional Parameters

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

Examples

The following code example checks the value of the FileFormat property to determine whether the workbook is a normal workbook. If the workbook is a normal workbook, then the example calls the SaveAs method to resave the workbook as an XML spreadsheet with the name XMLCopy.xls in the path specified by the Path property.

This example is for a document-level customization.

Private Sub WorkbookSaveAs()
    If Me.FileFormat = Excel.XlFileFormat.xlWorkbookNormal Then 
        Me.SaveAs(Me.Path & "\XMLCopy.xls", _
            Excel.XlFileFormat.xlXMLSpreadsheet, _
            AccessMode:=Excel.XlSaveAsAccessMode.xlNoChange)
    End If 
End Sub
private void WorkbookSaveAs()
{
    if (this.FileFormat == Excel.XlFileFormat.xlWorkbookNormal)
    {
        this.SaveAs(this.Path + @"\XMLCopy.xls",
            Excel.XlFileFormat.xlXMLSpreadsheet, missing, missing,
            false, false, Excel.XlSaveAsAccessMode.xlNoChange,
            missing, missing, missing, missing, missing);
    }
}

.NET Framework Security

See Also

Reference

Workbook Class

Workbook Members

Microsoft.Office.Tools.Excel Namespace