Excel VBA - A button to save a copy of current file


I am looking for a way to include an automatic record button in an Excel spreadsheet. This button would automatically save a copy of the current sheet in a given directory by adding to the original file name the date and time, e.g "my_file_24102007_0830.xls"


Public Sub CommandButton1_Click()  
Dim nom As String 
    nom = Day(Date) & "-" & Month(Date) & "-" & Year(Date) & "_" & ActiveWorkbook.Name 
    ActiveWorkbook.SaveCopyAs ActiveWorkbook.Path & "\" & nom 
    rep = MsgBox("You database has been saved : " & name, vbYes + vbInformation, "Copy of spreadsheet") 
End Sub

Thanks to gbinforme for this tip
Published by aakai1056. Latest update on June 25, 2012 at 07:38 AM by aakai1056.
This document, titled "Excel VBA - A button to save a copy of current file," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (https://ccm.net/).
Multiple Excel Files are automatically opened at startup
Excel - A Macro to copy and paste data in next blank cell