I was successful in modifying your spreadsheet to allow Modifying the spreadsheet (including UNDO) without stopping the timers and without crashing Excel.
The use of formulas to implement API Timer is courtesy of Jaafar Tribak
See May 27, 2009 post #3 in https://www.mrexcel.com/board/thread...t-cell.392397/
Thank you Jaafar
Please note that 'real time' code is difficult to debug, so there may still exist some unwanted 'side effects'. Please let me know if you have any problems.
Notes:
a. Implemented two timers only - Client Tasks 1 and 2.
Multiple Timers can run simultaneously or there is a limit of one 'Active Timer' only - chosen by a PERMANENT VBA change. See Sub LogicallyStopAllTimers() for instructions.
Whether one or multiple Logical Timers, there is only one SetTimer() Timer running.
b. Sub AdjustValue() in code module ModOriginal was changed to xAdjustValue() to avoid a conflict with a modified routine in code module ModNew.
c. The remainder of Sheet2 Code module VBA was NOT changed - Reset should work exactly as before.
d. Client Timer1 and Timer2 code was commented out in Code Module ModOriginal.
e. When Deleting Sheets Runtime Error Occurs (50290 = Application-defined or object-defined error) but is trapped by the software.
How the software works:
a. One API Timer is used using API code SetTimer() and KillTimer().
SetTimer() creates a timer that repeats at a specified interval until stopper by KillTimer().
b. Your data design was left intact as much as possible. VBA code affects Sheet 'Data_tab' as follows using 'Client Timer 1' as an example:
(1) Cell X3 = No change
(2) Column W = No change
(3) Cell V3 contains the formula '=NOW() - Data_tab!U3' when Timer1 is active
(3) Cell V3 = the VALUE that was in cell V3 when STOP was Clicked
(4) CellU3 = the Baseline (when Start was Clicked) Date and Time when Timer1 is active
(4) CellU3 = BLANK when Timer1 is NOT active
c. Sub APITimerEventHandler() runs each wake cycle of the generic timer (approximately at 1 second intervals)
APITimerEventHandler() causes 'Calculate' to occur for each active timer (e.g. Cell V3 for Client Timer1.
The use of 'Calculate' instead of writing to the spreadsheet directly allows Spreadsheet changes including Adding Sheets and UNDO while the Timer is running.
It is recommended that Suspend/Resume be used when Deleting Sheets.
d. Modifying VBA while the Timer is active can cause Excel to crash. The use of the 'Suspend' and 'Resume' CommandButtons can stop this from happening.
e. Occassionally Runtime Error '50290 Application-defined or object-defined error' occurs. 'On Error Resume Next' (i.e. ignoring the error) seems to mitigate the problem.
Important code excerpts follow. See the attached file for complete code:
Additional remarks and suggestions:
a. File with passwords take a lot of extra time to debug. Do not implement passwords until debugging is completed.
b. To prevent typos from ruining days and weeks of work 'Option Explicit' is NEEDED at the top of each code module. This prevents errors caused by missspellings and FORCES every variable to be DECLARED (e.g. Dim i as Integer). https://www.excel-easy.com/vba/examp...-explicit.html
Lewis
Due to space limitations some code is continued in the next reply.
Bookmarks