Mangesh Walhe Member since 2018 15 posts
Posted: 1 year ago
Last activity: 1 year 9 months ago

What's the correct approach to close ExcelConnector on which Macro is still running?

I have projects that have following as a common theme:

  1. Start a WindowsAdapter for Excel.EXE in monitorAll.
  2. Start a ExcelConnector, and run macros through it. (Using Parallel Process)
  3. Wait for pop-ups generated during Macro processing and click appropriate buttons using controls interrogated under WindowsAdapter.

I understand that it might not be the safest way to implement, but that's what has been implemented.

Problem somes when we run accross a error, for example we are waiting for popup screen1, and popup screen9 comes up. The WaitForEvent on screen1.created times out, and enters the error path. Mind you, the Excel macro hasn't finished processing yet as buttonA on screen1 was not pressed for it to proceed and finish processing.

In the end of error path, we try close->stop ExcelConnector and stop WindowsAdapter. There we end up having a COM exception on Close(), as Target excel has a macro still runnning.

We tried bypassing Close() and going to Stop() directly by sensing whether Macro is still running. (Crude way of Boolean Flag, Set it to true before XL.RunMacro() and reset to False after RunMacro()), but we still get the exception because it seems that ExcelConnector.Stop() implicitly calls Close() before Quit().

So we are thinking of using SendKeys with 'Ctrl+Break' to force stop macro if its running, but have been asked whether there is a better approach. (It has a risk of SendKeys not working in certain situations)

Has anyone used a different approach to achieve this??

CAUTION:A word of advice. I have seen many Closed threads wherein people are trying to do something similar and I STRONGLY RECOMMEND TO AVOID using above approach. It might work, but opens a Pandora's Box of lot of other problems, which are at times impossible to comprehend. Best is to replicate Macro logic using PEGA robotic components.

Robotic Process Automation
Moderation Team has archived post
Share this page LinkedIn