Export (0) Print
Expand All

Workbook.SaveAs Method

Office 2007
Saves changes to the workbook in a different file.

Syntax

expression.SaveAs(FileName, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, AddToMru, TextCodepage, TextVisualLayout, Local)

expression   A variable that represents a Workbook object.

Parameters

NameRequired/OptionalData TypeDescription
FilenameOptionalVariantA string that indicates the name of the file to be saved. You can include a full path; if you don't, Microsoft Excel saves the file in the current folder.
FileFormatOptionalVariantThe file format to use when you save the file. For a list of valid choices, see the XlFileFormat enumeration. 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.
PasswordOptionalVariantA case-sensitive string (no more than 15 characters) that indicates the protection password to be given to the file.
WriteResPasswordOptionalVariantA string that indicates the write-reservation password for this file. If a file is saved with the password and the password isn't supplied when the file is opened, the file is opened as read-only.
ReadOnlyRecommendedOptionalVariantTrue to display a message when the file is opened, recommending that the file be opened as read-only.
CreateBackupOptionalVariantTrue to create a backup file.
AccessModeOptionalXlSaveAsAccessModeThe access mode for the workbook.
ConflictResolutionOptionalXlSaveConflictResolutionAn XlSaveConflictResolution value that determines how the method resolves a conflict while saving the workbook. If set to xlUserResolution, the conflict-resolution dialog box is displayed. If set to xlLocalSessionChanges, the local user's changes are automatically accepted. If set to xlOtherSessionChanges, the changes from other sessions are automatically accepted instead of the local user's changes. If this argument is omitted, the conflict-resolution dialog box is displayed.
AddToMruOptionalVariantTrue to add this workbook to the list of recently used files. The default value is False.
TextCodepageOptionalVariantNot used in U.S. English Microsoft Excel.
TextVisualLayoutOptionalVariantNot used in U.S. English Microsoft Excel.
LocalOptionalVariantTrue saves files against the language of Microsoft Excel (including control panel settings). False (default) saves files against the language of Visual Basic for Applications (VBA) (which is typically US English unless the VBA project where Workbooks.Open is run from is an old internationalized XL5/95 VBA project).

Remarks

Use strong passwords that combine upper- and lowercase letters, numbers, and symbols. Weak passwords don't mix these elements. Strong password: Y6dh!et5. Weak password: House27. Use a strong password that you can remember so that you don't have to write it down

Example

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

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



Community Additions

ADD
Show:
© 2014 Microsoft