Re-protect sheet automatically after a certain time

anihak

New Member
Joined
Oct 6, 2010
Messages
29
Although I am used to write and manipulate vba macros, I have never used timer properties or functions.

What I would like to do is have a simple macro, activated by a button, that will unprotect a sheet of my workbook, and the reprotect it automatically after, say, 30 minutes.

Is that possible? :confused:

Thanks a bunch!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Look at the timer events, keep the main macro separate and then use timer events to call the macro every 30 minutes. Here is an example of timer events, in this case it is counting down based on a value in a cell. If you have some knowledge of VBA then you should be able to adapt it.

Dim CountDown As Date
Sub Timer()
CountDown = Now + TimeValue("00:00:01")
Application.OnTime CountDown, "Reset"
End Sub
Sub Reset()
Dim count As Range
Set count = [A1] ' A1 contains the number of seconds for the countdown.
count.Value = count.Value - 1
If count <= 0 Then
MsgBox "Countdown complete."
Exit Sub
End If
Call Timer
End Sub
Sub DisableTimer()
On Error Resume Next
Application.OnTime EarliestTime:=CountDown, Procedure:="Reset", Schedule:=False
End Sub
 
Upvote 0
So here is what I got. It works. My problem is now that the 30 I entered doesn't translate to 30 minutes in real time. How can we do that?

Sub Timer()
ActiveSheet.Unprotect
Dim CountDown As Date
CountDown = Now + TimeValue("00:00:01")
Application.OnTime CountDown, "Reset"
End Sub
Sub DisableTimer()
On Error Resume Next
Application.OnTime EarliestTime:=CountDown, Procedure:="Reset", Schedule:=False
End Sub
Sub Reset()
Dim count As Long
count = 30
count = count - 1
If count <= 0 Then
Worksheets("rt").Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
False
MsgBox "Time is up."
Exit Sub
End If
Call Timer
End Sub

Many thanks!
 
Upvote 0

Forum statistics

Threads
1,224,526
Messages
6,179,322
Members
452,906
Latest member
Belthazar

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