Real Time Clock

rakupareek

New Member
Joined
Dec 29, 2023
Messages
38
Office Version
  1. 2016
Platform
  1. Windows
Hii
I am using following code for digital clock running real time
Sub clock()
Application.ScreenUpdating = False
Worksheets("Estimate").Range("J8").Value = Now
Application.OnTime Now + TimeValue("00:00:01"), "Clock"
Application.ScreenUpdating = True
End Sub

Private Sub Workbook_Open()
Worksheets("Estimate").Unprotect Password:="1234"
Call Clock
Worksheets("Estimate").Protect Password:="1234"
End Sub

Now my problem is:-
1. Screen flickering every second
2. When i unprotect sheet by putting password, The worksheet unprotect & protect automatically within second.
i can't edit in my worksheet.
please help me to resolve this.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Maybe if you explained the purpose of the idea someone can suggest an alternative approach. What you are doing makes no sense to me.
- Sheet opens, unprotects and then calls Clock
- Clock code runs in an instant and passes control back to the calling procedure
- Sheet gets protected. All of this probably happens in less than 1 second.
Not sure why you should expect anything else.
 
Upvote 0
I have inserted this clock in a invoice I want to print current time in invoice.
 
Upvote 0
Then I guess remove the protection and don't put it back on until some other point - perhaps when you close the file.
 
Upvote 0
But I want digital clock in my file
Please suggest
Dim SchedRecalc As Date

Sub Recalc()

With Sheet1.Range("A1")

.Value = Format(Time, "hh:mm:ss AM/PM")

End With

Call SetTime

End Sub

Sub SetTime()

SchedRecalc = Now + TimeValue("00:00:01")

Application.OnTime SchedRecalc, "Recalc"

End Sub

Sub Disable()

On Error Resume Next

Application.OnTime EarliestTime:=SchedRecalc, Procedure:="Recalc", Schedule:=False

End Sub
 
Upvote 0
Since time is only needed for printing, it's simpler to program the BeforePrint event in the ThisWorkbook module:
VBA Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    With Me.Worksheets("Estimate")
        .Protect Password:="1234", UserInterfaceOnly:=True
        .Range("J8").Value = Now
    End With
End Sub
This is all the code needed. Just that.

Artik
 
Upvote 0

Forum statistics

Threads
1,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

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