bring Excel to front?

C

Craig in NJ

This seems a stupid question, but from VBA code within Excel how do I
force my Excel spreadsheet window to the top? I've hunted very hard in
newsgroup archives & the web but can't find a solution that actually
works. For example, I thought this should work, but it doesn't:

Application.WindowState = xlMaximized
Application.ShowWindowsInTaskbar = True
Application.Visible = True
AppActivate Application.name

My application name is, of course, "Microsoft Excel".

The context is that my Excel spreadsheet's VBA code opens a webbrowser
( Dim IEwindow as SHDocVw.InternetExplorer ),
does a lot of work with that browser (visible=true), and periodically I
want to be able to force the Excel spreadsheet to be the top window
again so the user can see the progress of filling in the spreadsheet.
The IEwindow somehow stays on top.

FWIW, I'd be almost as satisified if I could minimize the IEbrowser
window without making it invisible (the user needs to be able to access
it if necessary), but I can't find any examples on how to do that
either.

Craig in NJ
 
C

Craig in NJ

Dick said:

I really appreciate that tip, Dick. It worked out pretty well. Of
course, good leads are rarely as easy as they seem at first. There
were a couple of tricks to it:

Neither FindWindow("XLMAIN", Application.Caption) nor
FindWindow("XLMAIN", vbNullString) could find the Excel window, but
FindWindow(vbNullString, Application.Caption) could.

I had to follow each ShowWindow with a DoEvents in order to see an
effect.

I found I can also use ShowWindow to control my IEwindow webbrowser
window. I use IEwindow.HWND directly for that instead of Findwindow.
The result is that I now have some control over the layering order of
my IEwindow, Excel window, and anything else that might come up in the
meanwhile.

Thanks again!

Craig in NJ
 
D

Dick Kusleika

Craig
I really appreciate that tip, Dick. It worked out pretty well. Of
course, good leads are rarely as easy as they seem at first. There
were a couple of tricks to it:

Neither FindWindow("XLMAIN", Application.Caption) nor
FindWindow("XLMAIN", vbNullString) could find the Excel window, but
FindWindow(vbNullString, Application.Caption) could.

I had to follow each ShowWindow with a DoEvents in order to see an
effect.

I found I can also use ShowWindow to control my IEwindow webbrowser
window. I use IEwindow.HWND directly for that instead of Findwindow.
The result is that I now have some control over the layering order of
my IEwindow, Excel window, and anything else that might come up in the
meanwhile.
Thanks for the update. I'm going to add that to my site for future
generations. I'm surprised about the DoEvents, but I'll check it out first.
If I find anything earth-shattering, I'll let you know.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top