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

itr674

Well-known Member
Joined
Apr 10, 2002
Messages
1,782
Office Version
  1. 2016
Platform
  1. Windows
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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

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.
 
Upvote 0

itr674

Well-known Member
Joined
Apr 10, 2002
Messages
1,782
Office Version
  1. 2016
Platform
  1. Windows
dk - I believe that will do the trick, thanks ...
 
Upvote 0

Forum statistics

Threads
1,186,932
Messages
5,960,646
Members
438,491
Latest member
rachym95

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