VBA - Launching/Closing of the pages on Internet Explorer

Ask a question

This demo allows:
  • To open an instance of Internet Explorer
  • To open a page (URL in the cell)
  • Substitute by other page.
  • Note that it also has a timer


Add the reference:
  • Microsoft Internet Controls
  • In the VBA Editor>> Tools>> Reference and select' Microsoft Internet Controls"

The Macro

Sub OuvrirFermerPageIE() 
Dim Cel As Range, Plage As Range 
Dim Start As Single, Delay As Integer 
Dim IE As InternetExplorer 
    'La plage où se trouve les liens 
    Application.DisplayAlerts = False 
    Set Plage = Sheets("Feuil1").[A1:A5] 
    Delay = Sheets("Feuil1").[G8].Value 
    If Delay = 0 Then Delay = 15 
    Set IE = New InternetExplorer 
    IE.Visible = True 
    On Error GoTo IEfermerOuErreur 'si ont ferme le navigateur 
    For Each Cel In Plage 
        'Ouvrir la page 
        IE.Navigate Cel.Value 
        'Attendre que la page soit prète 
        While IE.ReadyState <> READYSTATE_COMPLETE 
        'Timer (Wait ralenti les autres appli) 
        Start = Timer + Delay ' pour 15 seconde 
        While Timer < Start 
    Next Cel 
    'Fermer le navigateur 
    Set IE = Nothing 
    Application.DisplayAlerts = True 
End Sub

Note: This macro can work in another Office application but you will need to enter the URL


Demo: Excel 97-2003 Workbook: here
Works on Excel 2007

Excel - Read data from another sheet
Excel 2007 - Insert an image with transparency