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

December 2016

Issue


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"

Solution


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

Related :

This document entitled « Excel VBA - A button to save a copy of current file » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.