save with date

  • Thread starter Thread starter ksnapp
  • Start date Start date
K

ksnapp

here is the code

Sub dater()

Dim fname

Range("a1").Select
Selection = "=NOW()"

fname = Worksheets("sheet1").Range("A1").Value
fname = fname & ".xls"
ChDir "C:\WINNT\Profiles\u436825\Desktop"
ActiveWorkbook.SaveAs FileName:=fname
End Sub

it is supposed to put the date in cell a1 and then save the file wit
the date as the name. It gets an error on the last line

anyhelp appreciated
 
Is your date in cell $A$1 formatted as mm/dd/yyyy? You cannot use slashes in
a filename, and will need to write a routine to replace them with something
else (i.e. "-"). See the Help topic "Guidelines for naming workbooks".
 
ksnapp said:
here is the code

Sub dater()

Dim fname

Range("a1").Select
Selection = "=NOW()"

fname = Worksheets("sheet1").Range("A1").Value
fname = fname & ".xls"
ChDir "C:\WINNT\Profiles\u436825\Desktop"
ActiveWorkbook.SaveAs FileName:=fname
End Sub

it is supposed to put the date in cell a1 and then save the file with
the date as the name. It gets an error on the last line

The default date string contains invalid characters for a filename.
Change the date format, for example:-

Range("a1").Select
Selection = "=NOW()"
Selection.NumberFormat = "ddmmyyyy hh-mm"
fname = Selection.Text & ".xls"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top