CLOCK - can I protect a sheet that has this code on it?

itr674

Well-known Member
Joined
Apr 10, 2002
Messages
1,778
I am using the below code to update an INTRO sheet that has current world times of a few places we to business.

I have two buttons, "Clock Update" and "Stop Clock".

Problem-when I protect the sheet and then press the Update Clock button I get a run time error of 1004. I gather this is telling me it can't run a macro using this button on a protected sheet?

Is there anyway around this??

I don't let the clock run all the time because it causes the screen to jump every time the clock updates ...<pre>Option Explicit
Dim NextTick
Sub ClockStart()
Run ("ClockUpdate")
End Sub
Sub ClockStop()
' Cancels the OnTime event (stops the clock)
Application.OnTime NextTick, "ClockUpdate", , False
End Sub
Sub ClockUpdate()
Application.ScreenUpdating = False
' Updates the clock that's visible
' DIGITAL CLOCK
ThisWorkbook.Sheets("fil-INTRO Sheet-4").Range("ESTDigitalClock").Value = CDbl(Time)
' Set up the next event one second from now
NextTick = Now + TimeValue("00:01:00")
Application.OnTime NextTick, "ClockUpdate"
Application.ScreenUpdating = True
End Sub</pre>
This message was edited by em on 2002-10-28 10:56
This message was edited by em on 2003-01-31 23:49
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

dk

MrExcel MVP
Joined
Feb 15, 2002
Messages
2,942
Hi,

You can unprotect and then protect your code in the procedure i.e.


Code:
Sub ClockUpdate()
Application.ScreenUpdating = False
'   Updates the clock that's visible
'   DIGITAL CLOCK
    ThisWorkbook.Sheets("fil-INTRO Sheet-4").Unprotect Password:=""
    ThisWorkbook.Sheets("fil-INTRO Sheet-4").Range("ESTDigitalClock").Value = CDbl(Time)
'   Set up the next event one second from now
    ThisWorkbook.Sheets("fil-INTRO Sheet-4").Protect Password:=""
    NextTick = Now + TimeValue("00:01:00")
    Application.OnTime NextTick, "ClockUpdate"
Application.ScreenUpdating = True
End Sub


If you have a password then be sure to type it into the above code.
 

Forum statistics

Threads
1,144,431
Messages
5,724,303
Members
422,543
Latest member
TimB_13

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