A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
I would like to first clarify that this is a user-to-user support forum, and we are not Microsoft support. Moderators here do not have backend access and cannot directly intervene in Microsoft products or perform escalations. We can only provide technical guidance and best-practice recommendations based on reported issues.
Hi @Гудулин Виталий Дмитриевич
Based on your description, I understand that calling IUIAutomation::AddFocusChangedEventHandler from an external process forces Excel (versions 2010–2024) to execute formula recalculations directly on the UI thread. This causes severe unresponsiveness on large workbooks, and crucially, Excel fails to clean up its internal subscription state even after unsubscribing or killing the external calling process. The only current resolution is to restart Excel.
Here are the analysis and guidance based on technical research of Excel's UI architecture:
From a broader technical standpoint, AddFocusChangedEventHandler can act as a system-wide listener that introduces significant inter-process communication (IPC) overhead. Excel's UI thread is notoriously sensitive and heavily intertwined with its drawing and synchronous event-handling loops, especially when automatic recalculation is running on complex workbooks.
However, there is currently no official public documentation, Microsoft KB article, or developer release note classifying this specific unsubscription failure. I Since there is no official API method exposed to force Excel to flush its internal UIA event listener cache without a restart, you can try the following structural workarounds to reduce the performance impact:
Before executing your external UIA tool, programmatically or manually switch Excel to Manual Calculation mode (Application.Calculation = xlCalculationManual). This prevents Excel from triggering heavy recalculation chains on the UI thread every time a focus event fires. If possible, run the target workbook in a completely separate Excel instance so that if a freeze occurs or a restart is required, it does not interrupt the user's main Excel workspace.
To get this behavior analyzed by engineering teams, I highly recommend reporting this behavior directly to Github.
Thank you for your contribution and patience.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click ""Comment"".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.