excelvbapopupoffice-addinscom-interop

Click OK or X (close) button on Excel COM Add-in pop up message with VBA or Windows API VBA


I have some familiarity with Excel VBA but this seems like a non-trivial issue. Namely, I have a corporate COM Add-In that is used to pull data from database. We've got a simple macro that utilizes this Add-Ins objects, methods and properties that opens the connection to database but when executed an in-built pop up window is displayed just to confirm the action. It's not a MsgBox, it doesn't even have the title bar, it seems native to the COM Add-In architecture. It's modal so the only way to continue execution is to acknowledge or close this pop-up. Unfortunately I can't provide any screenshots. I was thinking about running a loop to gather open windows prior to unning the macro and then run the loop again to check if any new windows appeared, problem is when this pop-up appears, code execution is halted...


Solution

  • Your VBA will not be able to intercept the popup and do actions programmatically because the code is executed on the main UI thread in Office applications.

    You can develop an external executable application which could monitor the active window in Excel and click the required control programmatically when required. That application could be run by your VBA code before getting such popups.

    Also you may ask for any publicly available methods provided by add-in developers. See Walkthrough: Call code in a VSTO Add-in from VBA for more information.