Unprotect Sheet / Enter Time Stamp / Protect Sheet in Macro

dshadel

New Member
Joined
Aug 2, 2007
Messages
17
I am trying to make a spread sheet to record start/stop times. I do not want my users to be able to do anything except click a button that activates the macro to do the time stamp.

If a make seperate macros to unprotect the worksheet, do the time stamp, and then protect the worksheet again, it works fine.


Sub Unprotect()
'
ActiveSheet.Unprotect Password:="123"
End Sub


Sub Time()
'
ActiveCell.Application.SendKeys ("^; ^+;~"), True
End Sub


Sub Protect()
'
ActiveSheet.Protect Password:="123"
End Sub


If I combine the commands into one macro, it doesn't work.


Sub StampTime()
'
ActiveSheet.Unprotect Password:="426"
ActiveCell.Application.SendKeys ("^; ^+;~"), True
ActiveSheet.Protect Password:="426"
End Sub


I'm not sure what else to try. I don't do much work in vb so hopefully I'm just missing something simple.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I sometimes have issues with sendkeys perhaps this will help.

Code:
Activesheet.Unprotect "426"
ActiveCell.Value = Now
Activesheet.Protect "426"
 
Upvote 0
I need the time entered to be static so it can be logged. I don't think I can accomplish this with the now function.

I think you're right about the SendKeys being the problem, though...
 
Upvote 0
The Function "NOW" in a formula is not static like you say, but when used in a code, the result will remain static until the code is run again.
 
Upvote 0
This would not be static

Code:
ActiveCell.formula = "=Now()"

but this is slightly different

Code:
ActiveCell.Value = Now


Edit - BTW, This would have the same effect as the ActiveCell.Value = Now approach

Code:
ActiveCell.Formula = "=Now()"
ActiveCell.Copy
ActiveCell.PasteSpecial xlPasteValues
 
Upvote 0

Forum statistics

Threads
1,214,988
Messages
6,122,620
Members
449,092
Latest member
amyap

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