Date & Time Formula

blandreth

Board Regular
Joined
Jan 18, 2018
Messages
56
Office Version
  1. 365
I'm looking for a simple excel formula that will populate a cell with the date and time when the file is opened.

I appreciate the feedback.

Brian
 
Thanks.

I am not good at writing code. I can modify to meet my needs if I get a starting point. So the code would look like this:

Sub SaveFile()
'
' SAVEFILE Macro
'Dim sNameSheet As String

sNameSheet = Range("NAME").Value

Sheets(“report”).Range(“G13”).Value=Now()

ActiveWorkbook.SaveAs Filename:="C:\Users\Brian.landreth\Documents\Weld Reports\2019 Weld Reports" & sNameSheet

'
End Sub
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Yes, that is what I am talking about (it isn't writing any code - just dropping the code I gave you in there).
Just try to think of it in logical steps. If you want the date/time stamp to be part of the file you are saving, that needs to happen BEFORE the file is saved.
The lines of code in VBA run in the order they are found in.
 
Upvote 0
Ok, I copied and pasted the line of code and it is now getting hung up at this line. Not sure what I'm doing wrong.
 
Upvote 0
Do you really have slanted quote marks here?
Code:
[COLOR=#333333]Sheets(“report”).Range(“G13”).Value=Now()[/COLOR]
VBA does not like those. Replace them with the straight up and down ones, like in my original post (").
Code:
[COLOR=#333333]Sheets("report").Range("G13").Value=Now()[/COLOR]
 
Last edited:
Upvote 0
That was it. When I copied it in, it must have put the slanted quote marks in.

Thanks again for all of your help. I greatly appreciate it!!!
 
Upvote 0
Sorry, but I found one more thing I have a question about. If I protect the cell to keep someone from changing the date formula it stops the code from working. If the cell is not locked the code works perfect. What can I do to make the code work with the cell locked.

Thanks!
 
Upvote 0
You need to unlock it before updating the cell, and then relock it afterwards.

So the structure will look like:
Code:
Sub SaveFile()
'
' SAVEFILE Macro
'Dim sNameSheet As String


sNameSheet = Range("NAME").Value


ActiveSheet.Unprotect "password", True, True
Sheets("report").Range("G13").Value = Now()
ActiveSheet.Protect "password"


ActiveWorkbook.SaveAs Filename:="C:\Users\Brian.landreth\Documents\Weld Reports\2019 Weld Reports" & sNameSheet


'
End Sub
Make sure to replace "password" with your actual password.
 
Upvote 0
It's getting hung up on the first line: ActiveSheet.Unprotect "password", True, True

Also, I know to protect the sheet it ask for a password and then confirmation of the password. Not sure if that makes a difference with the code
 
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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