macro code help saving with date and time in sheet name

markster

Well-known Member
Joined
May 23, 2002
Messages
579
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi - I need some help with some code that I need to add to a wider back up macro that I created. Basically, I need my macro to save but also include the time of saving (I can get it to add the date automatically but can't figure out how to get it to add the time). Can anyone help?
M
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Are you wanting the date and time to be saved in a cell somewhere? In which case:
Code:
Range("A1") = Date & " " & Time
Should do it.
 
Upvote 0
hi mate - the date and time won't actually be in the spreadsheet at all. I just need it to prefix the save name with it.
Cheers
 
Upvote 0
Hi mate as follows:

.SaveAs Filename:="C:\" & ws.Name & " " & Day(Now) & "-" & Month(Now) & "-" & Year(Now)
.Close

Cheers
M
 
Upvote 0
.SaveAs Filename:="C:\" & ws.Name & " " & Date & Time

Should do the trick
 
Upvote 0

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

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