View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Bernie Deitrick Bernie Deitrick is offline
external usenet poster
 
Posts: 5,441
Default How to save Excel, using macro which takes the name from a cell contained in it?

Reza,

You could use an event to automatically save the file when a value is entered into cell A1: copy the
code below, right-click the sheet tab, and select "View Code" then paste the code in the window that
appears. Change the path to reflect the desired path....

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address < "$A$1" Then Exit Sub
Application.DisplayAlerts = False
ThisWorkbook.SaveAs "C:\Excel\" & Target.Value & ".xls"
End Sub

HTH,
Bernie
MS Excel MVP


wrote in message ps.com...
How to save Excel as, using a macro which takes the name from a cell
contained in it?

Actually based on one of the postings here I can see that the following
script does the job.

ActiveWorkbook.SaveAs Filename:=Range("A1").Value

However I am wondering:

1- How can the path (directory/folder) can be incorporated in the
above?

2- How the above script can be executed automatically as soon as a name
is entered in the
"A1" cell for instance? Or even being saved after a specific time or
even conditional to an
other action?

Many thanks for your kind advice.

Cheers,

Reza.