macro code help saving with date and time in sheet name

markster

Well-known Member
Joined
May 23, 2002
Messages
575
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

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Lewiy

Well-known Member
Joined
Jan 5, 2007
Messages
4,284
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

markster

Well-known Member
Joined
May 23, 2002
Messages
575
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
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

markster

Well-known Member
Joined
May 23, 2002
Messages
575
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi mate as follows:

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

Cheers
M
 
Upvote 0

Lewiy

Well-known Member
Joined
Jan 5, 2007
Messages
4,284
.SaveAs Filename:="C:\" & ws.Name & " " & Date & Time

Should do the trick
 
Upvote 0

Forum statistics

Threads
1,190,919
Messages
5,983,585
Members
439,852
Latest member
balasat

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
Top