ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro Filename as Date (https://www.excelbanter.com/excel-programming/330850-macro-filename-date.html)

Donkin[_5_]

Macro Filename as Date
 

I have the following Macro, which saves the file to the entry in Cell
AG13.

The Cell AG13 is formatted as a date and I would like to use the macro
but cannot format the filename as a date, when I try it saves as
“False.xls”

Range("ag13").Select

savename = ActiveCell.Value & ".xls "

ActiveWorkbook.SaveAs Filename:= _
"C:\" & savename, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False



Any help would be appreciated.


--
Donkin
------------------------------------------------------------------------
Donkin's Profile: http://www.excelforum.com/member.php...o&userid=23715
View this thread: http://www.excelforum.com/showthread...hreadid=376258


Bob Phillips[_7_]

Macro Filename as Date
 
savename = Format(ActiveCell.Value,"yyyymmdd") & ".xls "


--
HTH

Bob Phillips

"Donkin" wrote in
message ...

I have the following Macro, which saves the file to the entry in Cell
AG13.

The Cell AG13 is formatted as a date and I would like to use the macro
but cannot format the filename as a date, when I try it saves as
“False.xls”

Range("ag13").Select

savename = ActiveCell.Value & ".xls "

ActiveWorkbook.SaveAs Filename:= _
"C:\" & savename, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False



Any help would be appreciated.


--
Donkin
------------------------------------------------------------------------
Donkin's Profile:

http://www.excelforum.com/member.php...o&userid=23715
View this thread: http://www.excelforum.com/showthread...hreadid=376258




FastOneBaz[_10_]

Macro Filename as Date
 

You can't have "/" in your filename and since these are likely to be i
your date you can't have them.


If your date is in cell B4, you could try this:



FileName = Range("B4").value

FileName = replace(Filename,"/","")

activeworkbook.saveas filename & ".xls

--
FastOneBa
-----------------------------------------------------------------------
FastOneBaz's Profile: http://www.excelforum.com/member.php...nfo&userid=973
View this thread: http://www.excelforum.com/showthread.php?threadid=37625


Norie

Macro Filename as Date
 

How is the date formatted in the cell?

If it has any /'s in it then it may not be valid as a filename.

You could try something like this.

Code
-------------------

savename = Format(Range("ag13").Value, "ddmmyyyy")

-------------------

--
Nori
-----------------------------------------------------------------------
Norie's Profile: http://www.excelforum.com/member.php...fo&userid=1936
View this thread: http://www.excelforum.com/showthread.php?threadid=37625



All times are GMT +1. The time now is 12:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com