Super simple macro to save with date, but prompt for the rest of the file name?

MikeyW1969

Board Regular
Joined
Apr 28, 2014
Messages
80
Hi all,
I'm trying to set up a basic document for when I purchase IT supplies. Everything is pretty simple, and I don't need macros for this, except that it would be kind of nice to have it auto-save the file every time in the same format I've been trying to use.

Here's an example of the filename format: Office Cabling and Supplies_Nov 29_2017
And I'll be saving it in my 'My Documents' folder, in a folder called 'Purchasing'.

So how do I set it up to prompt for the first part of the name(Office Cabling and Supplies), but then auto-append the date? I'm guessing that this one is pretty basic, I just seem to be missing that one thing...
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
something like...

Code:
Workbook.SaveAs(InputBox("Filename?")&"_"&YEAR(NOW())&"_"&MONTH(NOW())&"_"&DAY(NOW())&".xlsx")
I forgot but you should google how to pull the year, day and month seperately and then you just concatenate it all. My code above is pseudo code.

edit: Oh and you will also need to prepend the directory...

Code:
Workbook.SaveAs("C:\wherever\"&InputBox("Filename?")&"_"&YEAR(NOW())&"_"&MONTH(NOW())&"_"&DAY(NOW())&".xlsx")
 
Last edited:
Upvote 0
That worked. I was getting an "Object Required 424" error(In case anyone else tries this), and I had to change Workbook.SaveAs to ActiveWorkbook.SaveAs and that did it. Thank you!
 
Upvote 0
OK great, yeah my code was pseudo, I wrote from memory basically, without referencing the proper functions. Pseudo code is just used to transmit an idea rather than the exact character for character solution. ;)

Glad it worked out!

Also the code I wrote does not handle any unexpected input so that can cause errors if someone presses cancel or types in characters not permitted by windows to be used for filenames so it would need error handling if other users would run this code. Or a warning to not use special character, etc. The design is up to you but just fyi.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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