Saves a copy of the workbook to a file but doesn't modify the open workbook in memory.
Syntax
expression.SaveCopyAs (FileName)
expression A variable that represents a Workbook object.
Parameters
Name | Required/Optional | Data type | Description |
---|---|---|---|
FileName | Required | Variant | Specifies the file name for the copy. |
Example
The following example saves a copy of the active workbook.
ActiveWorkbook.SaveCopyAs "D:\TEMP\XXXX.XLSX"
The following example saves a copy of the active workbook with specify file name.
Sub BackupWorkbook()
Dim MyFileName As String, MyFileExt As String, MyNewFileName As String
MyFileName = ThisWorkbook.Name
MyFileExt = Right(MyFileName, Len(MyFileName) - InStrRev(MyFileName, "."))
MyNewFileName = Left(MyFileName, InStrRev(MyFileName, ".") - 1) & "_" & Format(Date, "d mmm yyyy")
ThisWorkbook.SaveCopyAs Filename:=ThisWorkbook.Path & "\" & MyNewFileName & "." & MyFileExt
End Sub