Opening a protected view workbook stops my timer that is is running in another opened workbook

Indominus

Board Regular
Joined
Jul 11, 2020
Messages
82
Office Version
  1. 2016
Platform
  1. Windows
Hello. So I have a workbook that tracks break times. It does this by counting down from 20 minutes in column E when a value is entered in column A. It is updated every single second. However, when a workbook that is in Protected View and needs to have "Enable editing" selected opens then I get run time error 91, "Object variable or with block variable not set" under the line

ActiveSheet.Range("E3").Calculate

After this the timer will not work on this workbook unless both files are closed and the protected view is removed. How could I edit these codes to remove the protected view and keep calculating the active sheet. Or just identify the sheet that needs the second by second calculation which is titled "Track Break Times.?"

Here are my module codes and then my private subs saved in the workbook
VBA Code:
Sub UpdateTime()
    ActiveSheet.Range("E3").Calculate
    Call Timer
End Sub

Sub Timer()
    Application.OnTime Now + TimeValue("00:00:01"), "UpdateTime"
End Sub

Sub StopTimer()
On Error Resume Next

Application.OnTime Now + TimeValue("00:00:01"), "UpdateTime", Schedule:=False

End Sub






Private Sub Workbook_Open()

UpdateTime

End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)


Call StopTimer

End Sub
 

Some videos you may like

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Jaafar Tribak

Well-known Member
Joined
Dec 5, 2002
Messages
8,069
Office Version
  1. 2016
Platform
  1. Windows
Try calling UpdateTime in the Workbook_Activate event handler instead of Workbook_Open
 

Watch MrExcel Video

Forum statistics

Threads
1,119,223
Messages
5,576,827
Members
412,748
Latest member
MikeyP14
Top