This project has moved. For the latest updates, please go here.


RunMacroSynchronization Timer is not stopped by SyncMacro


RunMacroSynchronization sets a timer when it's unable to run the SyncMacro but unfortunately there's an off-by-one error and the timer doesn't ever get killed:

Setting the timer (will always pass a timer ID of 0):
                bool runOK = COMRunMacro(_syncMacroName);
                if (!runOK && _timerId == 0)
                    // Timer not yet set - start it
                    // Timer will be stopped when SyncMacro actually runs.
                    IntPtr result = SetTimer(new HandleRef(_syncWindow, _syncWindow.Handle), timerId++, RETRY_INTERVAL_MS, IntPtr.Zero);
                    if (result == IntPtr.Zero)
                        // TODO: Handle unexpected error in setting timer
                        Debug.Print("SynchronizationWindow timer could not be set.");
Killing the timer (will always pass a timer ID of 1):
            // Check for timer and disable
            if (_timerId != 0)
                KillTimer(new HandleRef(_syncWindow, _syncWindow.Handle), _timerId);
                _timerId = 0;
It ends up calling the SyncMacro very frequently and I'm seeing this cause some weird rendering problems (particularly when Excel is in design mode and the user attempts to select an ActiveX button). It's clearly not the desired behaviour and I wonder if it could be causing other problems as well.


govert wrote Sep 30, 2014 at 2:12 PM


I'll have to look more closely, but I think this is a bug I was looking for a while back.

Thank you very much for finding it!


govert wrote Sep 30, 2014 at 9:16 PM

OK - this should be fixed in the latest check-in (81576).

Thank you again - this could not have been easy to track down.I really appreciate your effort.


sbyse wrote Oct 1, 2014 at 9:33 AM

Excellent, thanks for the quick response and fix.

I noticed your comment regarding adding the ability for users to register a callback to check for extra conditions before running the sync macro. That would certainly be useful for my purposes and probably for anyone else who wants to expose COM events. Fortunately it's possible to work around it by maintaining an additional queue so it's not essential.

Keep up the good work!


shrans007 wrote Sep 17, 2015 at 7:32 AM

Hi Govert,

I am facing the same issue in lastest 0.33+ version. anything i need to do to kill the timer ? its going in an infinite loop and hangs untill i kill the excel.

-Anshul Sharma

govert wrote Sep 17, 2015 at 9:04 AM

Hi Anshul,

I don't think it's the same issue. See the fixed code (which is the code for v 0.33) here:

Perhaps you have a mixture of versions, still running an old copy of the .xll?