WorkbookBase.SaveAs Method
Saves changes to the workbook in a different file.
Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.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 _
)
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
)
Parameters
filename
Type: System.ObjectThe 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.ObjectOne 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
Type: System.ObjectA case-sensitive string (no more than 15 characters) that indicates the protection password to be given to the file.
writeResPassword
Type: System.ObjectThe 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.Objecttrue to display a message when the file is opened, recommending that the file be opened as read-only.
createBackup
Type: System.Objecttrue to create a backup file.
accessMode
Type: XlSaveAsAccessModeOne of the XlSaveAsAccessMode values.
conflictResolution
Type: System.ObjectOne of the XlSaveConflictResolution values.
addToMru
Type: System.Objecttrue to add this workbook to the list of recently used files. The default value is false.
textCodepage
Type: System.ObjectNot used in U.S. English Excel.
textVisualLayout
Type: System.ObjectNot used in U.S. English Excel.
local
Type: System.Objecttrue 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 does not support saving a workbook as a shared workbook.
Optional Parameters
For information on optional parameters, see 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.xlsx 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.xml", _
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.xml",
Excel.XlFileFormat.xlXMLSpreadsheet,
false, false, Excel.XlSaveAsAccessMode.xlNoChange);
}
}
.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.