Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing an open objIE 2

Status
Not open for further replies.

fredmartinmaine

IS-IT--Management
Mar 23, 2015
79
0
0
US
In vbscript, I've opened a web doc for the user to have as a reference, like this:

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "C:\webpage.mht"

It pops right up and my script continues on, prompting user to verify some stuff from the page. Beautiful.

When I'm done, how do I close the page and make it go away?

I've tried stuff like objIE.quit, objIE.close, and even this:

set objIE = nothing

I thought that would kill it, but no. Mr. Google has stuff about searching for the right open IE doc and killing it, as if I wasn't the one that opened it in the first place but that seems like a crazy amount of work since I made the instance.

Missing something here, I'm sure.
 
o[tt]bjIE.Quit[/tt] should work if your variable still has connection to the object.
Try to add a line to be sure you are working with the same object:
[tt]Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True[/tt]

combo
 
That's the interesting thing, the browser shows up without having to set visible = true. It just appears anyway.

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "C:\webpage.mht"
objIE.Visible = True
objIE.Visible = False

Those Visible methods have no effect. The page opens in IE and stays there.
Tried the same with an html, had the same issue.

My testing vbs has only the above lines in it, so there's nothing else interfering unless it's in the environment.

Fred
 
Here's some news. If I change the URL I can get it to work.

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "msgbox("about to view")
objIE.visible = True
msgbox("do some work here")
objIE.visible = False

When I navigate to "C:\webpage.mht" or "C:\webpage.html" it definitely becomes visible without setting to true and ignores any effort to make is not visible.
 
What happens after changing order:
[tt]Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "C:\webpage.mht"[/tt]


combo
 
Test if you still have connection to internet explorer:
- Msgbox(objIE is Nothing),
- any of properties of objIE (LocationURL, Name, etc).

combo
 
The problem here is that you are trying to open an mhtml file (MHA), and this causes IE 11 to spawn a new IE instance - so the instance for which you have a reference is NOT the instance that is displaying the MHA. Basically you need to find the correct IE instance, which you can do through enumerating ShellWindows. ShellWindows can be accessed via code like

set objShell = CreateObject("shell.application")
set objShellWindows = objShell.Windows
 
I'm curious as to why it would spawn something new but also willing to just accept that it does, and roll with it.

So it opens visibly by itself and I need to find a way to close/quit it.

Based on your info I've come up with this:

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "C:\webpage.mht"

msgbox("do some work here")

set objShell = CreateObject("Shell.Application")
set objShWin = objShell.Windows

For Each foundthing in objShWin
If Instr(foundthing.LocationURL,"webpage.mht") Then
foundthing.Quit
End If
Next

It certainly works. I'll be playing around with a better test to be certain I have the right window.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top