Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Kill Internet Explorer Process

0

I have a macro which checks that the console on a server is available (the server is running ok)

Actualy 12 servers but who's counting.

While it is executing there are an Internet Explorer process and an Internet Explorer (32 bit) running. Which is fine I guess.

Once it is complete the Inernet Explorer process is not killed (the 32bit is killed ) and any subsequent attemt to run the macro fails with an unknown error until I go to the task manager and end the task myself. 

Here are the significant bits of the code.

Dim ie      As Object
TryThis = Worksheets("Servers").Cells(InRow, 2).Value
While TryThis <> ""
Set ie = New InternetExplorer
ie.navigate TryThis
<good stuff happend here>
ie.Quit 'Kill the internet explorer instance
wend
Set ie = Nothing

I don't mind calling any microsoft or cmd tool to kill this if required.

Thanks

Answer
Discuss

Answers

0
Selected Answer

Here are the changes that seem to work  

'change the dim
'Dim ie      As Object
Dim ie      As New InternetExplorer
TryThis = Worksheets("Servers").Cells(InRow, 2).Value
While TryThis <> ""
'remove this set
'Set ie = New InternetExplorer
ie.navigate TryThis
<good stuff happend here>
'remove the quit
'ie.Quit 'Kill the internet explorer instance
'no change to to show that I had this ;-)
 InRow = InRow + 1
TryThis = Worksheets("Servers").Cells(InRow, 2).Value
 
wend 
'move the quit outside the loop
ie.Quit 'Kill the internet explorer instance
 Set ie = Nothing
Discuss
0

Offhand, I would suggest to add

Set ie = Nothing

But that shouldn't cure the code's problem which seems to be in the use of While/Wend instead of If/End If.

The variant (?) TryThis is assigned a value before the While. That value doesn't seem to be changed in the loop (unless it's one of the "good things that happen"). This would cause an endless loop with the effect as you describe.

I point out that Microsoft has ceased supporting IE. Have you considered using the Dir function to check if a specific file or folder is available? It should make no difference to your purpose whether it isn't available because it's missing or the Server is.

Discuss

Discussion

Sorry there is no problem with the code loop I should also have left out the Wend or included the get next server addess. I included it only to indicate that I had the Set ie = Nothing around about the right place. 
So when it runs it opens launches the server consol in IE. The only problem is the orphaned Internet Explorer process still running as observed in the task manager. The good stuff consist of loops and test to wait for IE to respond and report the success fail back - also working well.
k1w1sm (rep: 197) Aug 28, '19 at 9:29 pm
Did you try Set ie = Nothing? It makes sense to me that one might be able to quit running an application without unloading it from memory.
Try stepping through the code with F8 on second running to identify the line which causes the "unknown error". Is there perhaps an Exit in the good code causing a jump over the Quit command in the last loop??
Variatus (rep: 4889) Aug 28, '19 at 9:56 pm
you should be able to see it in my orginal code snipet. the very last line. 
 
k1w1sm (rep: 197) Aug 28, '19 at 9:58 pm
Yes indeed. I did overlook that. But I would place it next to the Quit, within the loop. As it is, your loop creates many New instances of the ie object, relying on Quit to delete them, which I'm not sure it does. In my understanding deleting the object forces a Quit but not the other way around. So, Quit and Set = Nothing is a pair to appear in that sequence, possibly in both locations in your code where there is only one now.
Variatus (rep: 4889) Aug 28, '19 at 10:52 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login