Excel 2013 VBA - Macro to save a workbook as today's date and time

How can I write a sub so that it saves the current workbook as today's date and current time.
just like this:
2017-12-13 -- 2100.xlsm means that the file was saved on December 13, 2017 9:00 pm

This sub is not working.
What is wrong with it?
Can someone create the above code?

Sub FilenameDateTime()
ActiveWorkbook.SaveAs Format(Now(), "yyyy-m-d  h\.mm.xlsm"), FileFormat:=52
End Sub
brothertruffle880Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Try it like this...

Sub FilenameDateTime()
ActiveWorkbook.SaveAs Format(Now(), "yyyy-m-d  hhmm"), FileFormat:=52
End Sub

Open in new window


Since you are not providing the path/location, if ActiveWorkbook is the new workbook created during runtime, it will be saved at the default temp folder.

Or if you want to save the activeworkbook in the same location where the macro workbook is saved, try this...

Sub FilenameDateTime()
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & Format(Now(), "yyyy-m-d  hhmm"), FileFormat:=52
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brothertruffle880Author Commented:
Thanks!  PERFECT!
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.