VBA - Launching/Closing of the pages on Internet Explorer

December 2016




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

Prerequisites


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 
            DoEvents 
        Wend 
        'Timer (Wait ralenti les autres appli) 
        Start = Timer + Delay ' pour 15 seconde 
        While Timer < Start 
            DoEvents 
        Wend 
    Next Cel 
    'Fermer le navigateur 
    IE.Quit 
IEfermerOuErreur: 
    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

Download


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



Related :

This document entitled « VBA - Launching/Closing of the pages on Internet Explorer » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.