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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Emily

Active Member
Joined
Aug 28, 2002
Messages
304
Or Simply in the macro
Name = WorksheetFunction.Text(Date, "dd-mmm")
 

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
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>
 

sagain2k

Board Regular
Joined
Sep 8, 2002
Messages
94

ADVERTISEMENT

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
 

sagain2k

Board Regular
Joined
Sep 8, 2002
Messages
94

ADVERTISEMENT

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
 

Emily

Active Member
Joined
Aug 28, 2002
Messages
304
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.
 

JayMenon

New Member
Joined
Aug 21, 2002
Messages
19
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 !
 

Forum statistics

Threads
1,144,312
Messages
5,723,647
Members
422,508
Latest member
Lordkit1

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
Top