Add Date & Time Stamp to File Name When Saved

MikeeRDX

Board Regular
Joined
Feb 16, 2014
Messages
98
Hi,

I would like to have a date and time stamp as part of my file name whenever I click on a button to save my worksheet as a backup copy. I know how to do it with just a date, but I also would like to add a time stamp as well since the worksheet can be saved multiple times throughout the day. I would like to have a date & time stamp to save any updates as a file separate file. Is this possible and if so, how would you write the VBA code?

Thank you everyone for your help.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
How are you doing the backup copy now ?
With a macro ?
If so, post what code you already have.
If not, maybe this

Code:
Sub SaveIt()
Dim dt As String, wbNam As String
wbNam = ThisWorkbook.Name
dt = Format(Date, "yyy_mm_dd_hh_mm")
ActiveWorkbook.SaveAs Filename:=wbNam & " " & dt & ".xlsm"
End Sub
 
Upvote 0
Hi,

Thanks for your help. I used your code but this is what the file ends up saving as : WbName_09_16_2014_00_00_00.xlsm

The code I've been using is this:

Sub SaveMeDaily()
myDateStamp = Format(Date, "mmddyyyy")
FilePath = ThisWorkbook.Path & "/" & myDateStamp & ".xlsm"
ThisWorkbook.SaveCopyAs (FilePath)

End Sub
 
Upvote 0
Oops typo

Code:
Sub SaveMeDaily()
wbNam = ThisWorkbook.Name
myDateStamp = Format(Now(), "mmddyyyyhhmmss")
FilePath = ThisWorkbook.Path & "\" & wbNam & " " & myDateStamp & ".xlsm"
ThisWorkbook.SaveAs (FilePath)

End Sub
 
Last edited:
Upvote 0
Thank you for your help! It worked but the time is in military: 18 33. Anyway we can make that 6:33PM?
 
Upvote 0
Try
Code:
Sub SaveMeDaily()
wbNam = ThisWorkbook.Name
myDateStamp = Format(Now(), "d/mm/yyyy[$-409]h:mm:ss AM/PM")
FilePath = ThisWorkbook.Path & "\" & wbNam & " " & myDateStamp & ".xlsm"
ThisWorkbook.SaveAs (FilePath)

End Sub
 
Upvote 0

Forum statistics

Threads
1,218,626
Messages
6,143,582
Members
450,494
Latest member
GolfNut39

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