Question
![](/profiles/pega_profile/modules/pega_user_image/assets/user-icon.png)
Pegasystems Inc.
JP
Last activity: 27 Nov 2018 23:27 EST
What's the correct approach to close ExcelConnector on which Macro is still running?
I have projects that have following as a common theme:
- Start a WindowsAdapter for Excel.EXE in monitorAll.
- Start a ExcelConnector, and run macros through it. (Using Parallel Process)
- 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)
I have projects that have following as a common theme:
- Start a WindowsAdapter for Excel.EXE in monitorAll.
- Start a ExcelConnector, and run macros through it. (Using Parallel Process)
- 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.