共用方式為


WorkbookBase.SaveAs Method

Definition

Saves changes to the workbook in a different file.

public void SaveAs (object filename, object fileFormat, object password, object writeResPassword, object readOnlyRecommended, object createBackup, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode accessMode, object conflictResolution, object addToMru, object textCodepage, object textVisualLayout, object local);
member this.SaveAs : obj * obj * obj * obj * obj * obj * Microsoft.Office.Interop.Excel.XlSaveAsAccessMode * obj * obj * obj * obj * obj -> unit
Public Sub SaveAs (Optional filename As Object, Optional fileFormat As Object, Optional password As Object, Optional writeResPassword As Object, Optional readOnlyRecommended As Object, Optional createBackup As Object, Optional accessMode As XlSaveAsAccessMode, Optional conflictResolution As Object, Optional addToMru As Object, Optional textCodepage As Object, Optional textVisualLayout As Object, Optional local As Object)

Parameters

filename
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
Object

One of the XlFileFormat values that specifies the file format to use when you save the file. 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
Object

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

writeResPassword
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
Object

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

createBackup
Object

true to create a backup file.

accessMode
XlSaveAsAccessMode

One of the XlSaveAsAccessMode values.

conflictResolution
Object

One of the XlSaveConflictResolution values.

addToMru
Object

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

textCodepage
Object

Not used in U.S. English Excel.

textVisualLayout
Object

Not used in U.S. English Excel.

local
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).

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.xlsx in the path specified by the Path property.

This example is for a document-level customization.

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

Remarks

Visual Studio does not support saving a workbook as a shared workbook.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

Applies to