In VBA, make IE Browser object always in foreground

G

gary

I use VBA to create an IE Browser object using code shown below.
Sometimes the browser comes up minimized and shows flashing in the task bar
at the bottom of the screen due to other activities on the screen.

I need to have the ie object always visible. Is there a command I can use
to make this happen ?


Set ie = CreateObject("InternetExplorer.Application")
ie.AddressBar = False
ie.MenuBar = False
ie.Toolbar = False
ie.Width = ScreenWidth * 0.55 ' 600
ie.Height = ScreenHeight * 0.98 '750
ie.Left = 0
ie.Top = 0

Thanks,

Gary
 
C

Chip Pearson

You need to add

IE.Visible = True

to make the browser visible in the first place. To keep the
browser visible within Excel, allowing you to switch between IE
and Excel without losing the browser, you need to use the
SetParent API call.

In the declarations area of your module (above and outside of any
procedure), declare the SetParent function.

Declare Function SetParent Lib "user32" (ByVal hWndChild As Long,
_
ByVal hWndNewParent As Long) As Long

Then, in your procedure, use code like

IE.Visible = True
SetParent IE.Hwnd, Application.Hwnd

This will make IE a child window of the Excel application, and IE
will float above the worksheet.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
G

gary

Hi Chip,

Your suggestion worked great with one small mod. I had to Add “Private†in
front of the declare SetParent function so as to not get the “..Declare
statements not allowed as public members of object modules†error. I don’t
understand what this message is telling me. But your suggest worked great.

Many thanks,

Gary
decalre teh
 
C

Chip Pearson

In class modules, Sheet modules, and the ThisWorkbook module,
function declares may not be Public. You must declare them as
Private. Just one of the rules of the road.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
G

gary

Chip,

I noticed that although the IE browser is on top, I can not move it or
adjust the scroll bars. If I comment out the “SetParent IE.Hwnd,
Application.Hwnd†then I can move the window and adjust the scroll bars.

Is it possible to have the browser window on top AND still be able to
control the scroll bars and move the window.

Hope this makes sense,

Gary
 
C

Chip Pearson

I can't replicate your problem The code I provided works fine in
Excel 2003 and IE 6.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 

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