Save date as filename

HBorenz

New Member
Joined
May 18, 2002
Messages
2
Goog Evening,

I'm trying to save my workbook with the current date as the filename.
I use this macro
Sub SaveAsA1()
Name=Range("A1").value
Activeworkbook.SaveAs Filename:=Name

I put =now() in cell A1, and format it as 9-Sep, but it does not work.

Any help would be greatly appreaciated,

Thanks
Harlan
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Emily, you could use VBA's Format function for this as well, instead of the long text for the Text worksheetfunction...

<pre>Name = Format(Date, "dd-mmmm")</pre>
 
Upvote 0
Try this out...it will save the current date as a text value and assign it to a variable you can use for the filename. Note also that you could change the "mm" and "yy" etc.. date format characters as needed. Hope this helps! Cheers,

--Ray

Sub testdatetext()

'Saves the current sheet with the current date as the filename

Dim fname

ActiveCell.Formula = "=Text(Now(), ""m""""-""""dd""""-""""yy"")"
'This captures the current date as text into the active cell, but
'to really convert it to text that can be used in filename do these
'extra steps too

Selection.Copy 'copies the active cell

'PASTES AS TEXT ONLY VALUE THAT CAN BE USED AS A FILE OR RANGENAME LATER
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False

fname = Selection 'assigns the variable fname to the selection
'fname could now be used as a filename

End Sub
 
Upvote 0
Thanks Juan, Emily... those methods are much simpler and very useful! Juan, when I tried the example:

Name = Range("A1").Text

for a numeric value, the result seemed to still be numeric rather than text only...

Thanks again for all the great tips!!!

-R
 
Upvote 0
On 2002-09-11 20:52, Juan Pablo G. wrote:
Emily, you could use VBA's Format function for this as well, instead of the long text for the Text worksheetfunction...

<pre>Name = Format(Date, "dd-mmmm")</pre>

Thanks. I forgot the "format" function.
 
Upvote 0
Hi !!

If the question is still unanswered. Please try the following code. It works well !!

Sub filesave()
ActiveWorkbook.SaveAs (Format(Date, "dd-mm-yy"))
End Sub

Regards !
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top