Question about saving a workbook with a macro

Colombo

Board Regular
Joined
Apr 21, 2003
Messages
54
I've got a question about saving a workbook with a macro. I can save the workbook fine with the macro. What I would like to do is have the macro generate the file name based upon a given text & add the month year into the title of the file name.

So for example, I want to save the file name as "Feb 2003 Monthly Report.xls"

Is there anyway to setup the macro to use the date function or something else to generate the Feb 2003 based upon the current month, or possibly by looking at a cell in the workbook?

Thanks in advance for any help.

Josh
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
In VBA, you can generate the current Month and Date in the format you requested like this:

Code:
MyDate = Format(Now(), "mmm") & " " & Year(Now())
 
Upvote 0
This will do the job

ThisWorkbook.SaveAs (Format(Month(Now()), "mmm") & " " & Format(Year(Now()), "####") & " Your File Name.xls")

GNaga
 
Upvote 0
I can actually make the formula I posted even simpler:

Code:
MyDate = Format(Now(), "mmm yyyy")
 
Upvote 0
If you want to use a cell.... name a cell in the workbook as Filename

place the following formula in the cell =TEXT(TODAY(),"mmm yyyy")&" Monthly Report"

then use the following macro

Code:
Sub filesaver()


ActiveWorkbook.SaveAs FileName:=Range("Filename").Value


End Sub
 
Upvote 0
gnaga said:
This will do the job

ThisWorkbook.SaveAs (Format(Month(Now()), "mmm") & " " & Format(Year(Now()), "####") & " Your File Name.xls")

GNaga

Thanks for the code. I've got a weird problem though. It saves it as Jan 2003. My date on the my computer is correct, any ideas why it's doing this?


jmiskey said:
MyDate = Format(Now(), "mmm yyyy")

That worked. Thanks


WillR said:
If you want to use a cell.... name a cell in the workbook as Filename

place the following formula in the cell =TEXT(TODAY(),"mmm yyyy")&" Monthly Report"

then use the following macro


code:
--------------------------------------------------------------------------------
Sub filesaver()


ActiveWorkbook.SaveAs FileName:=Range("Filename").Value


End Sub
--------------------------------------------------------------------------------

WillR,

Just a quick question, how do I name a cell in the workbook. After looking at how the report will be generated, I think this would be a better way to go.

I have the date coming back from an external database in the format YYYYMM. If I can manipulate that date format into the mmm yyyy format and use it in the file name, I think that would work the best.

Thanks everyone for the help.

Josh
 
Upvote 0
To name a cell click the cell u want to call ie A1 then click insert > name > define > then type the name of the cell that being Filename A1 now = filename

yayyyyy I knew an answer!!!
 
Upvote 0
One more quick question.

I've got the macro saving the workbook by refrencing the cell I've named Filename.

I want to save the workbook in a folder based off the cell I've called "Foldername"

Do I need to modify the
ActiveWorkbook.SaveAs Filename:=Range("Filename").Value

Or do I go about doing that.

Thanks

Josh
 
Upvote 0

Forum statistics

Threads
1,221,711
Messages
6,161,450
Members
451,707
Latest member
PedroMoss2268

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