Hi there,
The following code will save a copy of the workbook which contains this routine, as an Excel workbook with whatever filename is specified in the SaveAs dialog box:
Option Explicit
Sub SaveCopyOfThisWorkbook()
Const sFILE_FILTER As String = "Excel Files (*.xlsx), *.xlsx"
Dim vNewFileName As Variant
Dim sNewFileName As String
Dim iErrorNo As Long
vNewFileName = Application.GetSaveAsFilename(FileFilter:=sFILE_FILTER)
If vNewFileName <> False Then
sNewFileName = CStr(vNewFileName)
On Error Resume Next
ThisWorkbook.SaveCopyAs Filename:=sNewFileName
iErrorNo = Err.Number
On Error GoTo 0
If iErrorNo = 0 Then
MsgBox "The file """ & sNewFileName & """ has been saved", vbInformation
Else: MsgBox "An error occurred - the copy workbook has NOT been saved", _
vbExclamation
End If
End If
End Sub
The copy workbook will be saved as an Excel workbook (i.e. macro-free).
An error message will be displayed if (for whatever reason) the copy file fails to save successfully.
If you wish to save the copy workbook as a Macro-Enabled workbook the FileFilter statement should be changed as follows:
Const sFILE_FILTER As String = "Excel Macro-Enabled Workbook (*.xlsm), *.xlsm"
Hope this helps - please let me know how you get on.
Regards,
Greg M
Bookmarks