• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA code to save a file with current date and the name in a range

sn152

Member
Hi All,

I am trying to save a file with a name given in a cell D12 in sheet1 and with the current date. (eg: Report - 28/8/2014
Please let me know the code for this.

Thanks in advance.
 
Hi,

Try the below code

You may need to change the path

Code:
Sub Saveas()
 
  Dim Filename

  Filename = Sheets("Sheet1").Range("D12").Value

  ActiveWorkbook.Saveas Filename:=ActiveWorkbook.Path & "/" & Filename & ".xlsx"
 
End Sub
 
Hi,

Try the below code

Code:
Sub Saveas()
 
  Dim Filename
  Sdate = " - " & Format(Date, "dd/mm/yyyy")
  Filename = Sheets("Sheet1").Range("D12").Value
  ActiveWorkbook.Saveas Filename:=ActiveWorkbook.Path & "/" & Filename & Sdate & ".xlsx"
 
End Sub
 
Iam getting an error stating wrong number of arguments or invalid property assignment. And this error occurs in the key word "Format".
 
Hi,

Try this

Note: File name will not accept "/"

Code:
Sub Saveas()
 
  Dim Filename
  Dim sdate
  sdate = " - " & VBA.Format(Date, "dd-mm-yy")
  Filename = ActiveWorkbook.Sheets("Sheet1").Range("D12").Text
  ActiveWorkbook.Saveas Filename:=ActiveWorkbook.Path & "/" & Filename & sdate & ".xlsx"
 
End Sub
 
Back
Top