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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close Excel In Explorer by VBA

Status
Not open for further replies.

GlennUK

MIS
Joined
Apr 8, 2002
Messages
2,937
Location
GB
Hi all,

I've searched the threads here but haven't been able to spot the solution to this ...

I have user that has got an Excel workbook on an Intranet page, which loads in an Explorer window. So far so good. She has a macro she wants to run that saves the file and closes the Explorer window.

Application.Quit does the job for a workbook open in Excel, but what command should be used to shut the Explorer window with the workbook in it?



Cheers, Glenn.

My grandfather was ill, and my grandmother smeared goose-grease on his back. He went downhill very quickly after that.
 
Glenn,

Have you created an ie object?
Code:
   Dim ie As Object
   Set ie = CreateObject("InternetExplorer.application")

   '...stuff

   ie.Quit
   Set ie = Nothing


Skip,

[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue]
 
Hi Skip,

that does not do it. It still leaves the workbook open in an Internet Explorer session.




Cheers, Glenn.

My grandfather was ill, and my grandmother smeared goose-grease on his back. He went downhill very quickly after that.
 
You'll have to first Quit the ie and then Quit the Excel App, since the code is running in Excel.

Skip,

[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue]
 
What you say makes sense Skip, but it doesn't actually do it.

I tried it with an Application.Quit in there too, and that shuts down Excel ( as that is where it runs the code ), but it still leaves the workbook open in the Explorer window.

I tried this myself, and couldn't get it to work, but told my user about your suggestions in case her setup for the real application was different, so that she could try it, and she couldn't get to work either.

Any more ideas would be gratefully received.



Cheers, Glenn.

My grandfather was ill, and my grandmother smeared goose-grease on his back. He went downhill very quickly after that.
 
How is the IE object created, that the Excel object is running in. I just used CreateObject as an example. If the Excel object is ALREADY running within the IE object, then you'll have to use GetObject to Set the IE object in your code. It's got to be the RIGHT object in order to properly manipulate it.

Skip,

[glasses] [red]Be advised:[/red] When transmitting sheet music...
If it ain't baroque, don't fax it! [tongue]
 
it'd be the GETOBJECT then. If I am reading Glen right, a user is IN IE to start with - they then open up the excel workbook FROM IE so IE is actually the host App with Excel running INSIDE it

Rgds, Geoff

Yesterday it worked. Today it is not working. Windows is like that.

Please read FAQ222-2244 before you ask a question
 
Hi Geoff, you are right, that's what's happening.

I'll have a search on GETOBJECT and see what some experimentation gets me.




Cheers, Glenn.

My grandfather was ill, and my grandmother smeared goose-grease on his back. He went downhill very quickly after that.
 
Seems to work very nicely as Skip has already given the syntax (although he has left out an important comma....)

Code:
Dim myIE As Object

Set myIE = GetObject(, "InternetExplorer.application")
myIE.Quit

Set myIE = Nothing

is what I experimented with and it certainly shut down IE

Rgds, Geoff

Yesterday it worked. Today it is not working. Windows is like that.

Please read FAQ222-2244 before you ask a question
 
Hi Glenn (and All),

The problem with GetObject comes when you have multiple instances of IE (or whatever it is) - and it's not uncommon for people to have multiple browser windows open.

GetObject returns the first instance it finds and there is no way to control which one that might be, so I think you will find the results inconsistent.

To guarantee the right instance I think you will need to know the window handle - which you might be able to get as you are running inside it. I'm afraid my knowledge doen't run far enough to tell you how to actually do it [wink]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Just a though:
Application.Parent.Quit

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for you comment Tony, that's the problem, the code kills the first instance of IE, and that is never going to be the one with the Excel workbook in it.

I'm not going to do any more on this until I find out whether the user had found a workaround or not.

Thanks to all for your help.



Cheers, Glenn.

My grandfather was ill, and my grandmother smeared goose-grease on his back. He went downhill very quickly after that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top