Sub timeStamp1()
Dim ws As Worksheet
Set ws = ActiveSheet
ws.Unprotect Password:="whatever"
ActiveCell.Value = Now
ActiveCell.Offset(0, 1) = Environ("USERNAME")
ws.Protect Password:="whatever"
End Sub
If you are not using a password to protect the sheet, you can remove that part of the code. The obvious drawback is that this code puts the password "out there". So, if you are concerned about security, you would need to lock the VB project itself with a password to keep knowledgeable folks from hacking it.
A (only slightly) less vulnerable method would be to use a "hidden" Name to contain the password. (You could remove the code after using it one time.)
Sub hideMyPassword()
Dim nm As Name
On Error Resume Next
ActiveWorkbook.Names.Add _
Name:="pwd", _
RefersToR1C1:="=whatever", _
Visible:=False
End Sub
Then, use this version of the code:
Sub timeStamp2()
Dim ws As Worksheet
Dim pwd As String
Dim nm As Name
Set nm = ThisWorkbook.Names("pwd")
pwd = Right(nm.RefersTo, Len(nm.RefersTo) - 1)
Set ws = ActiveSheet
ws.Unprotect Password:=pwd
ActiveCell.Value = Now
ActiveCell.Offset(0, 1) = Environ("USERNAME")
ws.Protect Password:=pwd
End Sub
A person would have to be pretty knowledgable about VBA to get at your password using this. But, on the downside, this method acutally makes your password [B][I]less[B][I] secure than the above method (if the above is combined with locking the VBProject).
Bookmarks