A few words of thanks would be greatly appreciated.

Excel - A macro to record button


I would like to create a command button "Record" in an Excel file.
When someone click on the button , the macro takes the cell where the person has entered his name and cell containing the respective date and save the data in a workbook.


  • Open your workbook
  • Open the VBA Alt F11
  • Double left click on ThisWorkbook in the top left
  • Right click in right window

Copy the code below in this window

Sub Macro_Enregistrement()   
Dim Nom_Fichier, Chemin, Reponse   
'A definir   
Chemin = "C:\............\"   
'A1 et A2 a changer suivant vos besoin   
Nom_Fichier = Worksheets("Feuil1").Range("A1") & Worksheets("Feuil1").Range("A2") & ".xlsm"   

retval = MsgBox("Voulez- vous enregistrer ce fichier: " & Nom_Fichier & " ?", vbYesNo)   
If retval = 6 Then   
Reponse = "Fichier " & Nom_Fichier & " sauvegardé"   
ActiveWorkbook.SaveAs Filename:=Chemin & Nom_Fichier, _   
FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False   
Reponse = "Fichier non sauvegardé"   
End If   
retval = MsgBox(Reponse)   
End Sub   
  • Create a button and assign the macro.

Thanks to f894009 for this tip.

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jean-François Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.
This document, titled « Excel - A macro to record button », is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (ccm.net).

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!