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

August 2017

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


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 (ccm.net).