-1

Is there a way to trigger macro by the escape key that is used to interrupt the ongoing procedure? I found nothing on the subject on the internet.

I have a procedure that opens Internet Explorer in not visible mode. It's pulling data from pages. Now when user interrupts the procedure the Internet Explorer remains open. I need to shut it down if user chooses to interrupt for whatever reason. Can someone point me in the right direction?

Lance
  • 203
  • 2
  • 15
  • Use Error Handling- `On Error GoTo Err_Exit` then on exit set your object to Quit – 0m3r May 11 '16 at 09:02
  • Interruption is handled as an error? – Lance May 11 '16 at 09:17
  • how do you open the IE if you use the SHDocVw.InternetExplorer 'microsoft internet controls (shdocvw.dll) you can use .Quit also you can raise Errors programmatically -> http://stackoverflow.com/questions/26368883/how-to-stop-vba-code-execution-if-conditions-are-met – Doktor OSwaldo May 11 '16 at 10:59
  • Set IE = New InternetExplorerMedium Along the reference are Internet Controls and HTML object library I use quit at the end of macro. The problem is, that User can interrupt the macro and the iexplorer.exe remains open in process list. And the Om3r suggestion did not work. VBA doesn't handle interruption as an error, even if it did, the user interrupts the process so if exactly at the time of interruption code dictated to quit it would be stopped by the same thing - the interruption – Lance May 11 '16 at 11:31
  • In what application is this code running? What does a user do to interrupt the process? – Cindy Meister May 11 '16 at 17:21

1 Answers1

0

This will interrupt the hidden IE and close it.

Sub Test()
On error goto Out:

'Do Something

Exit Sub

Out:
    IE.quit
  'End
End Sub
Ricky
  • 98
  • 4