Saving
SaveAs
link - docs.microsoft.com/en-us/office/vba/api/excel.workbook.saveas
Allows you to save the workbook in a different format or with different attributes.
ActiveWorkbook.Save
ActiveWorkbook.SaveAs FileName:="C:\Temp\Wbk1.xls"
ActiveWorkbook.SaveAs Filename:="filename", _
FileFormat:=xlFileFormat.xlOpenXMLWorkbookMacroEnabled, _
Password:="", _
WriteResPassword:="", _
ReadOnlyRecommended:=False, _
CreateBackup:=False, _
AccessMode:=xlSaveAsAccessMode.xlNoChange, _
ConflictResolution:=xlSaveConflictResolution.xlLocalSessionChanges, _
AddToMru:=True, _
TextCodepage:="", _
TextVisualLayout:="", _
Local:=True, _
WorkIdentity:=
Filename - Variant. A 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.
FileFormat - A xlFileFormat value that specifies the file format to use. 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 - Variant. A case-sensitive string (no more than 15 characters) that indicates the protection password to be given to the file.
WriteResPassword - Variant. A 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.
ReadOnlyRecommended - Variant. True to display a message when the file is opened, recommending that the file be opened as read-only.
CreateBackup - Variant. True to create a backup file.
AccessMode - A xlSaveAsAccessMode value that determines the type of access that the file will have including an option for a shared workbook.
If this argument is omitted, the access mode isn't changed. This argument is ignored if you save a shared list without changing the file name. To change the access mode, use the ExclusiveAccess method.
ConflictResolution - A xlSaveConflictResolution value that determines how the method resolves a conflict while saving the workbook.
If this argument is omitted, the conflict-resolution dialog box is displayed.
AddToMru - Variant. True to add this workbook to the list of recently used files. The default value is False.
TextCodePage - Variant. Not used in Microsoft Excel.
TextVisualLayout - Variant. Not used in Microsoft Excel.
Local - Variant. True 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).
WorkIdentity - (Added in 365)
SaveCopyAs
ActiveWorkbook.SaveCopyAs "C:\temp\Copy.xlsm"
Workbooks("Book2.xls").SaveCopyAs ("C:\temp\Backup.xls")
Shared Workbooks
To make an Excel file available for shared use you must save the file using the SaveAs with AccessMode = xlShared
To terminate sharing the AccessMode xlExclusive is available.
Close without a prompt
You can change the Saved property of the workbook to True and Excel will think that there are no changes to be saved.
ActiveWorkbook.Saved = True
Save a Workspace
Saves the current workspace to the filename parameter.
Application.SaveWorkspace
Save ActiveSheet as PDF
Sub SaveActiveSheetsAsPDF()
Dim saveLocation As String
saveLocation = "C:\Users\marks\OneDrive\Documents\myPDFFile.pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=saveLocation
End Sub
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext