VBA - A button to save filename of a document to a cell

December 2016



Issue


I need to create a button that saves a modified document as a number in a particular cell (e.g in A6).

Solution


Private Sub CommandButton1_Click() 
  '.xlsm or xls depending if you want to save the macros. 
  ActiveWorkbook.SaveAs Filename:="c:\archive\" & Cells(1, 6) & ".xlsm" 
  Cells(1, 5) = "Archived" 
  If Cells(1, 5) = "Archived" Then 
    CommandButton1.Visible = False 
  End If 
End Sub 

Thanks to f894009 for this tip.

Related :

This document entitled « VBA - A button to save filename of a document to a cell » 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.