Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Closing an open objIE

Closing an open objIE

Closing an open objIE

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.

RE: Closing an open objIE

objIE.Quit 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:
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True


RE: Closing an open objIE

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.


RE: Closing an open objIE

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

Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "http://www.irs.gov"
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.

RE: Closing an open objIE

What happens after changing order:
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = True
objIE.Navigate "C:\webpage.mht"


RE: Closing an open objIE

No difference there.

RE: Closing an open objIE

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


RE: Closing an open objIE

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

RE: Closing an open objIE

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
End If

It certainly works. I'll be playing around with a better test to be certain I have the right window.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close