Opening a Web Page in IE Maximized and in the Same IE Window each time Excel VBA CODE is Exicuted

Naed1

New Member
Joined
Nov 15, 2013
Messages
26
I have been using the Followhyperlink command in VBA to open an Amazon web page. The code I was using is shown below

Code:
  MyAsin = Range("BM" & MyRow)
  Hyper = "http://www.amazon.com/gp/offer-listing/" & MyAsin & "/ref=olp_prime_used?ie=UTF8&shipPromoFilter=1&sort=sip&me=&seller=&condition=all"    
  ActiveWorkbook.FollowHyperlink Address:=Hyper, NewWindow:=False

This code had some problems where excel at times hangs. I Googled this and have found others have seen the same type of problem using the Followhyperlink funtion. I was not able to find a solution for this using FireFox. I did find a IE funtion that was suppose to work however. The code for opening the Amazon Webpage in an IE window is shown below.

Code:
 MyAsin = Range("BM" & MyRow)
  Hyper = "http://www.amazon.com/gp/offer-listing/" & MyAsin & "/ref=olp_prime_used?ie=UTF8&shipPromoFilter=1&sort=sip&me=&seller=&condition=all"
  
  Dim oIE As Object
  Set oIE = CreateObject("InternetExplorer.Application")
  oIE.navigate Hyper
  oIE.Visible = True
  Do While oIE.readyState <> 4
  Loop
  Set oIE = Nothing


Question 1

This seems to work but IE opens in a small window. I have opened IE directly with the IE Icon, close and reopen it several times each time maximizing it before I close it. IE then "Remembers" to open maximized. Once however I run the above code IE opens in a small window again.

How do I get IE to open Maximized in using the above code?

Question 2

Each time the above code is run it opens a new IE window for the New Amazon Web Page. FireFox was opening new tabs each time its Excel code was exicuted. I got around this in FireFox by configuring FireFox to display the new Web Page in a Single Tab if the the page was activated by an External Link (like using Followhyperlink in Excel)

Is there a way to have the new Web Page Displayed in the same IE Window each time the above code is run?
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
1. Add this at the top of the module above all procedures:
Code:
Private Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
and maximise IE using:
Code:
ShowWindow oIE.hWnd, vbMaximizedFocus

2. Loop through Shell.Windows looking for the IE window which matches your IE window (e.g. IE.LocationURL). There is example code on this forum.
 
Upvote 0
Code:
[COLOR=green]'Place at the very top of the code module[/COLOR]
[COLOR=darkblue]Declare[/COLOR] [COLOR=darkblue]Function[/COLOR] apiShowWindow [COLOR=darkblue]Lib[/COLOR] "user32" Alias "ShowWindow" _
            ([COLOR=darkblue]ByVal[/COLOR] hwnd [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR], [COLOR=darkblue]ByVal[/COLOR] nCmdShow [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]) [COLOR=darkblue]As[/COLOR] Long

Global [COLOR=darkblue]Const[/COLOR] SW_SHOWNORMAL = 1
Global [COLOR=darkblue]Const[/COLOR] SW_SHOWMINIMIZED = 2
Global [COLOR=darkblue]Const[/COLOR] SW_MAXIMIZE = 3
Code:
[COLOR=darkblue]Sub[/COLOR] IE()
    
    [COLOR=darkblue]Dim[/COLOR] oIE [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Object[/COLOR]
    
    MyAsin = Range("BM" & MyRow)
    Hyper = "http://www.amazon.com/gp/offer-listing/" & MyAsin & "/ref=olp_prime_used?ie=UTF8&shipPromoFilter=1&sort=sip&me=&seller=&condition=all"
    
[B]    [COLOR=darkblue]With[/COLOR] CreateObject("Shell.Application")
        [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] objItem [COLOR=darkblue]In[/COLOR] .Windows()
            [COLOR=green]'Check for existing IE[/COLOR]
            [COLOR=darkblue]If[/COLOR] UCase(objItem.FullName [COLOR=darkblue]Like[/COLOR] "*IEXPLORE.EXE") [COLOR=darkblue]Then[/COLOR]
                [COLOR=darkblue]Set[/COLOR] oIE = objItem.Application
                [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]For[/COLOR]
            [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
        [COLOR=darkblue]Next[/COLOR] objItem
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR][/B]
    
    [COLOR=green]'Create new instance of IE if it doesn't alredy exist[/COLOR]
    [COLOR=darkblue]If[/COLOR] oIE [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR] [COLOR=darkblue]Set[/COLOR] oIE = CreateObject("InternetExplorer.Application")
    
    oIE.navigate Hyper
    oIE.Visible = [COLOR=darkblue]True[/COLOR]
    [B]apiShowWindow oIE.hwnd, SW_MAXIMIZE [COLOR=green]'Maximize IE[/COLOR][/B]
    [COLOR=darkblue]Do[/COLOR] [COLOR=darkblue]While[/COLOR] oIE.readyState <> 4: DoEvents: [COLOR=darkblue]Loop[/COLOR]
    [COLOR=darkblue]Set[/COLOR] oIE = [COLOR=darkblue]Nothing[/COLOR]
  
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Upvote 0
Thanks,

I am using this code and it seems to work well. One problem it still has is that if I click on IE at the bottom of my screen (Windows 7) it shows multiple windows still open from each time I execute the code.

For now since the machine I am presently using has a lot of memory, I can run the code a bunch of times then right click on the IE Icon at the bottom of my screen and click Close all windows.

This will work for now but I would rather not have to do this but only have the last IE window still opened.

Any suggestions?
 
Upvote 0
Code:
[COLOR=green]'Place at the very top of the code module[/COLOR]
[COLOR=darkblue]Declare[/COLOR] [COLOR=darkblue]Function[/COLOR] apiShowWindow [COLOR=darkblue]Lib[/COLOR] "user32" Alias "ShowWindow" _
            ([COLOR=darkblue]ByVal[/COLOR] hwnd [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR], [COLOR=darkblue]ByVal[/COLOR] nCmdShow [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]) [COLOR=darkblue]As[/COLOR] Long

Global [COLOR=darkblue]Const[/COLOR] SW_SHOWNORMAL = 1
Global [COLOR=darkblue]Const[/COLOR] SW_SHOWMINIMIZED = 2
Global [COLOR=darkblue]Const[/COLOR] SW_MAXIMIZE = 3
Code:
[COLOR=darkblue]Sub[/COLOR] IE()
    
    [COLOR=darkblue]Dim[/COLOR] oIE [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Object[/COLOR]
    
    MyAsin = Range("BM" & MyRow)
    Hyper = "http://www.amazon.com/gp/offer-listing/" & MyAsin & "/ref=olp_prime_used?ie=UTF8&shipPromoFilter=1&sort=sip&me=&seller=&condition=all"
    
[B]    [COLOR=darkblue]With[/COLOR] CreateObject("Shell.Application")
        [COLOR=darkblue]For[/COLOR] [COLOR=darkblue]Each[/COLOR] objItem [COLOR=darkblue]In[/COLOR] .Windows()
            [COLOR=green]'Check for existing IE[/COLOR]
            [COLOR=darkblue]If[/COLOR] UCase(objItem.FullName [COLOR=darkblue]Like[/COLOR] "*IEXPLORE.EXE") [COLOR=darkblue]Then[/COLOR]
                [COLOR=darkblue]Set[/COLOR] oIE = objItem.Application
                [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]For[/COLOR]
            [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
        [COLOR=darkblue]Next[/COLOR] objItem
    [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR][/B]
    
    [COLOR=green]'Create new instance of IE if it doesn't alredy exist[/COLOR]
    [COLOR=darkblue]If[/COLOR] oIE [COLOR=darkblue]Is[/COLOR] [COLOR=darkblue]Nothing[/COLOR] [COLOR=darkblue]Then[/COLOR] [COLOR=darkblue]Set[/COLOR] oIE = CreateObject("InternetExplorer.Application")
    
    oIE.navigate Hyper
    oIE.Visible = [COLOR=darkblue]True[/COLOR]
    [B]apiShowWindow oIE.hwnd, SW_MAXIMIZE [COLOR=green]'Maximize IE[/COLOR][/B]
    [COLOR=darkblue]Do[/COLOR] [COLOR=darkblue]While[/COLOR] oIE.readyState <> 4: DoEvents: [COLOR=darkblue]Loop[/COLOR]
    [COLOR=darkblue]Set[/COLOR] oIE = [COLOR=darkblue]Nothing[/COLOR]
  
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]

Thanks,

I am using this code and it seems to work well. One problem it still has is that if I click on IE at the bottom of my screen (Windows 7) it shows multiple windows still open from each time I execute the code.

For now since the machine I am presently using has a lot of memory, I can run the code a bunch of times then right click on the IE Icon at the bottom of my screen and click Close all windows.

This will work for now but I would rather not have to do this but only have the last IE window still opened.

Any suggestions?
 
Upvote 0
Try changing this...
If UCase(objItem.FullName Like "*IEXPLORE.EXE") Then

To this
If UCase(objItem.FullName) Like "*IEXPLORE*" Then
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,298
Members
449,077
Latest member
Rkmenon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top