SaveAs Method

Applies To

Chart Object, DialogSheet Object, Module Object, Workbook Object, Worksheet Object.

Description

Saves changes to the sheet or workbook in a different file.

Syntax

object.SaveAs(filename, fileFormat, password, writeResPassword, readOnlyRecommended, createBackup, accessMode, conflictResolution)

object

Required. The object to which this method applies.

filename

Optional. A string indicating the name of the file to save. You can include a full path; if you do not, Microsoft Excel saves the file in the current folder.

fileFormat

Optional. The file format to use when you save the file. See the FileFormat property for a list of valid choices.

password

Optional. A case-sensitive string indicating the protection password to be given to the file. Should be no more than 15 characters.

writeResPassword

Optional. A string indicating 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

Optional. If True, when the file is opened, Microsoft Excel displays a message recommending that you open the file as read-only.

createBackup

Optional. If True, Microsoft Excel creates a backup file; if False, no backup file is created; if omitted, the status is unchanged.

accessMode

Optional. Specifies the workbook access mode. One of xlShared (shared list), xlExclusive (exclusive mode), or xlNoChange (do not change the access mode). If this argument is omitted, the access mode is not changed. This argument is ignored if you save a shared list without changing the filename. To change the access mode, use the ExclusiveAccess method.

conflictResolution

Optional. Specifies how change conflicts are resolved if the workbook is a shared list. One of xlUserResolution (display the conflict-resolution dialog box), xlLocalSessionChanges (automatically accept the local user's changes), or xlOtherSessionChanges (accept other changes in preference to the local user's changes). If this argument is omitted, the conflict-resolution dialog box is displayed.

See Also

FileFormat Property, MultiUserEditing Property, Save Method, SaveCopyAs Method, Saved Property.

Example

This example creates a new workbook, prompts the user for a filename, and then saves the workbook.


Set NewBook = Workbooks.Add
Do
    fName = Application.GetSaveAsFilename
Loop Until fName <> False
NewBook.SaveAs Filename:=fName