MrExcel Publishing
Your One Stop for Excel Tips & Solutions

naming a file with current month in title


Posted by Mark Henderson on January 30, 2002 12:32 PM

As part of one of my macros, I wish to finish by saving the file with the current month in the title.
e.g statistics_[thismonth.thisyear].xls which is how I want the format... displayed as statistics_january2002.xls . Any ideas?

adie
Mark


Posted by Larry on January 30, 2002 12:49 PM

****** To retrieve the current month, try this sample code. You will need to concatenate the month with the file name in your Save As routine,

MsgBox MonthName(Month(Now))

Posted by Larry on January 30, 2002 12:55 PM

More code for the Save As part

***** Here is sample for the Save As part:

Month_Name = MonthName(Month(Now))
Year_Num = Year(Now)

ActiveWorkbook.SaveAs Filename:= "C:\Directory Path\Statistics" & Month_Name & Year_Num & ".xls"

Posted by Gary Bailey on January 30, 2002 12:58 PM

How about

Dim strName As String
strName = "statistics_" & Format(Date, "mmmmyyyy") & ".xls"
ThisWorkbook.SaveAs strName

Gary As part of one of my macros, I wish to finish by saving the file with the current month in the title.

Posted by Mark Henderson on January 30, 2002 1:39 PM

Re: More code for the Save As part

Thank you :-) That works perfectly
Mark