VBA Help Please: If IE is closed my code breaks

Peter h

Active Member
Joined
Dec 8, 2015
Messages
417
I have some code that automates Internet Explorer. I have IE.Visible set to True so that the user can make sure all data is being entered correctly. The problem I'm running into is that if the user closes the IE before the sub is done running then at the end where I have IE.Quit, it breaks and gives me runtime error "Application has disconnected from client". So I wanted to put an If statement in to check if the IE window had been closed, but I can't seem to figure out exactly how to do it, which seems simple to me. I put this code, and it doesn't seem to work the way I was hoping.

Code:
If Not IE is Nothing Then
    IE.Quit
    Set IE = Nothing
Else
    Exit Sub
End If
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
If you just want to end without an error message then try:
Code:
On Error Resume Next
IE.Quit
On Error GoTo 0
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,286
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top